Skip to content

Commit

Permalink
Update to 1.21.3
Browse files Browse the repository at this point in the history
  • Loading branch information
Patbox committed Nov 8, 2024
1 parent ec1aaac commit 327b057
Show file tree
Hide file tree
Showing 70 changed files with 418 additions and 414 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@ jobs:
- name: Set up JDK
uses: actions/setup-java@v1
with:
java-version: 17
java-version: 21

- name: Grant execute permission for gradlew
run: chmod +x gradlew

- name: Build with Gradle
run: ./gradlew build

- uses: actions/upload-artifact@v2
- uses: actions/upload-artifact@v4
with:
name: artifacts
path: build/libs
4 changes: 2 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
- name: Set up JDK
uses: actions/setup-java@v1
with:
java-version: 17
java-version: 21

- name: Grant execute permission for gradlew
run: chmod +x gradlew
Expand All @@ -32,7 +32,7 @@ jobs:
run: ./gradlew build

- name: Upload GitHub release
uses: AButler/upload-release-assets@v2.0
uses: AButler/upload-release-assets@v3.0
with:
files: 'build/libs/*.jar;!build/libs/*-sources.jar;!build/libs/*-dev.jar'
repo-token: ${{ secrets.GITHUB_TOKEN }}
10 changes: 5 additions & 5 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
plugins {
id 'fabric-loom' version '1.4.+'
id 'fabric-loom' version '1.7.+'
id 'maven-publish'
}

sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
sourceCompatibility = JavaVersion.VERSION_21
targetCompatibility = JavaVersion.VERSION_21

archivesBaseName = project.archives_base_name
version = project.mod_version
Expand All @@ -28,7 +28,7 @@ dependencies {
modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}"

// Plasmid
modImplementation "xyz.nucleoid:plasmid:0.5.102-SNAPSHOT+1.20.4"
modImplementation "xyz.nucleoid:plasmid:0.6.0-SNAPSHOT+1.21.3"
//modImplementation "xyz.nucleoid:substrate:0.1.3"
//implementation include('kdotjpg:open-simplex:2.0')
}
Expand All @@ -49,7 +49,7 @@ tasks.withType(JavaCompile).configureEach {
it.options.encoding = "UTF-8"

// Minecraft 1.17 (21w19a) upwards uses Java 16.
it.options.release = 17
it.options.release = 21
}


Expand Down
10 changes: 5 additions & 5 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ org.gradle.jvmargs=-Xmx1G

# Fabric Properties
# check these on https://modmuss50.me/fabric.html
minecraft_version=1.20.4
yarn_mappings=1.20.4+build.1
loader_version=0.15.2
minecraft_version=1.21.3
yarn_mappings=1.21.3+build.1
loader_version=0.16.9

# Dependencies
fabric_version=0.91.1+1.20.4
fabric_version=0.106.1+1.21.3
# Mod Properties
mod_version=1.0.5
mod_version=1.1.0
maven_group=eu.pb4
archives_base_name=destroythemonument

Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.4-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.9-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
15 changes: 9 additions & 6 deletions src/main/java/eu/pb4/destroythemonument/DTM.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@
import net.minecraft.registry.RegistryKeys;
import net.minecraft.registry.tag.TagKey;
import net.minecraft.util.Util;
import xyz.nucleoid.plasmid.game.GameSpace;
import xyz.nucleoid.plasmid.game.GameType;
import xyz.nucleoid.plasmid.api.game.GameAttachment;
import xyz.nucleoid.plasmid.api.game.GameSpace;
import xyz.nucleoid.plasmid.api.game.GameType;
import net.minecraft.util.Identifier;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
Expand All @@ -27,12 +28,14 @@
import java.util.Set;
import java.util.WeakHashMap;

import static eu.pb4.destroythemonument.other.DtmUtil.id;

public class DTM implements ModInitializer {
public static final String ID = "destroy_the_monument";
public static final Logger LOGGER = LogManager.getLogger(ID);
public static final Random RANDOM = new Random();
public static final TagKey<Block> SPAWNABLE_TAG = TagKey.of(RegistryKeys.BLOCK, DtmUtil.id("spawnable"));
public static final TagKey<Block> BUILDING_BLOCKS = TagKey.of(RegistryKeys.BLOCK, DtmUtil.id("building_blocks"));
public static final TagKey<Block> SPAWNABLE_TAG = TagKey.of(RegistryKeys.BLOCK, id("spawnable"));
public static final TagKey<Block> BUILDING_BLOCKS = TagKey.of(RegistryKeys.BLOCK, id("building_blocks"));

private static final Hash.Strategy<Object> IDENTITY_HASH = new Hash.Strategy<Object>() {
@Override
Expand All @@ -51,12 +54,12 @@ public boolean equals(Object o, Object k1) {


public static final GameType<GameConfig> TYPE = GameType.register(
new Identifier(ID, ID),
Identifier.of(ID, ID),
GameConfig.CODEC,
WaitingLobby::open
);

public static final WeakHashMap<GameSpace, BaseGameLogic> ACTIVE_GAMES = new WeakHashMap<>();
public static final GameAttachment<BaseGameLogic> GAME_LOGIC = GameAttachment.create(id("game_logic"));

@Override
public void onInitialize() {
Expand Down
18 changes: 12 additions & 6 deletions src/main/java/eu/pb4/destroythemonument/blocks/DtmBlocks.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,24 @@
import net.minecraft.block.Blocks;
import net.minecraft.registry.Registries;
import net.minecraft.registry.Registry;
import net.minecraft.registry.RegistryKey;
import net.minecraft.registry.RegistryKeys;

import java.util.function.Function;

public class DtmBlocks {
public static final Block WEAK_GLASS = new WeakGlassBlock(AbstractBlock.Settings.copy(Blocks.GLASS).strength(0.2f, 0).dropsNothing());
public static final Block LADDER = new FloatingLadderBlock(AbstractBlock.Settings.copy(Blocks.LADDER));
public static final Block WEAK_GLASS = register("weak_glass", AbstractBlock.Settings.copy(Blocks.GLASS).strength(0.2f, 0).dropsNothing(), WeakGlassBlock::new);
public static final Block LADDER = register("ladder", AbstractBlock.Settings.copy(Blocks.LADDER), FloatingLadderBlock::new);

public static void register() {
register("weak_glass", WEAK_GLASS);
register("ladder", LADDER);

}

private static void register(String name, Block block) {
Registry.register(Registries.BLOCK, DtmUtil.id(name), block);
private static <T extends Block> T register(String name, AbstractBlock.Settings settings, Function<AbstractBlock.Settings, T> func) {
var id = DtmUtil.id(name);
var block = func.apply(settings.registryKey(RegistryKey.of(RegistryKeys.BLOCK, id)));
Registry.register(Registries.BLOCK, id, block);
return block;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.WorldView;
import xyz.nucleoid.packettweaker.PacketContext;

public class FloatingLadderBlock extends LadderBlock implements PolymerBlock {
public FloatingLadderBlock(Settings settings) {
Expand All @@ -18,12 +19,7 @@ public boolean canPlaceAt(BlockState state, WorldView world, BlockPos pos) {
}

@Override
public Block getPolymerBlock(BlockState state) {
return Blocks.LADDER;
}

@Override
public BlockState getPolymerBlockState(BlockState state) {
public BlockState getPolymerBlockState(BlockState state, PacketContext context) {
return Blocks.LADDER.getDefaultState().with(HorizontalFacingBlock.FACING, state.get(HorizontalFacingBlock.FACING));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import net.minecraft.util.hit.BlockHitResult;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import xyz.nucleoid.packettweaker.PacketContext;

public class WeakGlassBlock extends TransparentBlock implements PolymerBlock {
public WeakGlassBlock(Settings settings) {
Expand All @@ -25,8 +26,8 @@ protected void appendProperties(StateManager.Builder<Block, BlockState> builder)
}

@Override
public Block getPolymerBlock(BlockState state) {
return Blocks.GLASS;
public BlockState getPolymerBlockState(BlockState state, PacketContext context) {
return Blocks.GLASS.getDefaultState();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,26 @@

import eu.pb4.destroythemonument.other.DtmUtil;
import eu.pb4.polymer.core.api.entity.PolymerEntityUtils;
import net.fabricmc.fabric.api.object.builder.v1.entity.FabricEntityTypeBuilder;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityType;
import net.minecraft.entity.SpawnGroup;
import net.minecraft.registry.Registries;
import net.minecraft.registry.Registry;
import net.minecraft.registry.RegistryKey;
import net.minecraft.registry.RegistryKeys;

public class DtmEntities {
public static final EntityType<DtmTntEntity> TNT = FabricEntityTypeBuilder.create(SpawnGroup.MISC, DtmTntEntity::new).dimensions(EntityType.TNT.getDimensions()).fireImmune().build();
public static final EntityType<DtmTntEntity> TNT = register("tnt", EntityType.Builder.create(DtmTntEntity::new, SpawnGroup.MISC).dimensions(1, 1).makeFireImmune());

public static void register() {
register("tnt", TNT);
}

private static void register(String name, EntityType<?> block) {
Registry.register(Registries.ENTITY_TYPE, DtmUtil.id(name), block);
private static <T extends Entity> EntityType<T> register(String name, EntityType.Builder<T> func) {
var id = DtmUtil.id(name);
var block = func.build(RegistryKey.of(RegistryKeys.ENTITY_TYPE, id));
Registry.register(Registries.ENTITY_TYPE, id, block);
PolymerEntityUtils.registerType(block);
return block;
}

}
90 changes: 55 additions & 35 deletions src/main/java/eu/pb4/destroythemonument/entities/DtmTntEntity.java
Original file line number Diff line number Diff line change
@@ -1,39 +1,30 @@
package eu.pb4.destroythemonument.entities;

import com.google.common.collect.Sets;
import eu.pb4.destroythemonument.DTM;
import eu.pb4.destroythemonument.other.DtmUtil;
import eu.pb4.polymer.core.api.entity.PolymerEntity;
import net.minecraft.block.BlockState;
import net.minecraft.enchantment.ProtectionEnchantment;
import net.minecraft.entity.*;
import net.minecraft.entity.damage.DamageSource;
import net.minecraft.entity.data.DataTracker;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.projectile.ProjectileEntity;
import net.minecraft.fluid.FluidState;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.network.packet.s2c.play.ExplosionS2CPacket;
import net.minecraft.particle.ParticleTypes;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.sound.SoundEvents;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Box;
import net.minecraft.util.math.MathHelper;
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.GameRules;
import net.minecraft.world.BlockView;
import net.minecraft.world.World;
import net.minecraft.world.event.GameEvent;
import net.minecraft.world.explosion.EntityExplosionBehavior;
import net.minecraft.world.explosion.Explosion;
import net.minecraft.world.explosion.ExplosionBehavior;
import org.jetbrains.annotations.Nullable;
import xyz.nucleoid.plasmid.game.common.team.GameTeamKey;
import xyz.nucleoid.plasmid.util.PlayerRef;
import xyz.nucleoid.packettweaker.PacketContext;
import xyz.nucleoid.plasmid.api.game.common.team.GameTeamKey;
import xyz.nucleoid.plasmid.api.util.PlayerRef;

import java.util.Iterator;
import java.util.List;
import java.util.Optional;
import java.util.Set;


public class DtmTntEntity extends Entity implements PolymerEntity {
Expand Down Expand Up @@ -119,6 +110,11 @@ protected MoveEffect getMoveEffect() {
return MoveEffect.NONE;
}

@Override
public boolean damage(ServerWorld world, DamageSource source, float amount) {
return false;
}

public boolean canHit() {
return !this.isRemoved();
}
Expand All @@ -134,7 +130,7 @@ protected void writeCustomDataToNbt(NbtCompound nbt) {
}

@Override
protected void initDataTracker() {
protected void initDataTracker(DataTracker.Builder builder) {

}

Expand Down Expand Up @@ -222,35 +218,59 @@ protected void onBlockHit() {

private void explode() {
this.discard();

var explosion = new CustomExplosion(this.getWorld(), this, this.getWorld().getDamageSources().explosion(this, this.causingEntity), new EntityExplosionBehavior(this), this.getX(), this.getBodyY(0.0625D), this.getZ(), 2.8f, false, Explosion.DestructionType.DESTROY);
explosion.collectBlocksAndDamageEntities();
explosion.affectWorld(true);

if (!explosion.shouldDestroy()) {
explosion.clearAffectedBlocks();
}


for (var player : this.getWorld().getPlayers()) {
ServerPlayerEntity serverPlayerEntity = (ServerPlayerEntity)player;
if (serverPlayerEntity.squaredDistanceTo(this.getX(), this.getBodyY(0.0625D), this.getZ()) < 4096.0D) {
serverPlayerEntity.networkHandler.sendPacket(new ExplosionS2CPacket(this.getX(), this.getBodyY(0.0625D), this.getZ(), 3, explosion.getAffectedBlocks(), explosion.getAffectedPlayers().get(serverPlayerEntity), explosion.getDestructionType(), explosion.getEmitterParticle(), explosion.getParticle(), explosion.getSoundEvent()));
}
}
this.getWorld().createExplosion(this, this.getDamageSources().explosion(this, this.causingEntity), new CustomExplosionBehaviour(this), this.getBoundingBox().getCenter(), 2.8f, false, World.ExplosionSourceType.TNT);
}

protected float getEyeHeight(EntityPose pose, EntityDimensions dimensions) {
return 0.15F;
}

@Override
public EntityType<?> getPolymerEntityType(ServerPlayerEntity player) {
public EntityType<?> getPolymerEntityType(PacketContext context) {
return EntityType.TNT;
}


public static class CustomExplosion extends Explosion {
public static class CustomExplosionBehaviour extends EntityExplosionBehavior {
private final DtmTntEntity entity;

public CustomExplosionBehaviour(DtmTntEntity entity) {
super(entity);
this.entity = entity;
}

@Override
public Optional<Float> getBlastResistance(Explosion explosion, BlockView world, BlockPos pos, BlockState blockState, FluidState fluidState) {
var out = super.getBlastResistance(explosion, world, pos, blockState, fluidState);
return out.map(x -> blockState.isIn(DTM.BUILDING_BLOCKS) ? 0.8f : Math.max(2.8f, x));
}

@Override
public float getKnockbackModifier(Entity entity) {
return 1.4f;
}

@Override
public float calculateDamage(Explosion explosion, Entity entity, float amount) {
double x = entity.getX() - explosion.getPosition().x;
double y = (entity instanceof DtmTntEntity ? entity.getY() : entity.getEyeY()) - explosion.getPosition().y;
double z = entity.getZ() - explosion.getPosition().z;
double distance = Math.sqrt(x * x + y * y + z * z);

float doublePower = explosion.getPower() * 2.0F;
double w = Math.sqrt(entity.squaredDistanceTo(explosion.getPosition())) / (double) doublePower;

if (distance != 0.0D) {
double ac = (1.0D - w) * amount;
return (float) ((int) ((ac * ac + ac) / 2.0D * 3.2D * (double) doublePower + 1.0D) * (this.entity.causingEntity == entity ? 0.25 : 1));
}

return 0;
}
}


/*public static class CustomExplosion extends Explosion {
private final World world;
private final Entity entity;
private final double z;
Expand Down Expand Up @@ -365,5 +385,5 @@ public void collectBlocksAndDamageEntities() {
}
}
}
}
}*/
}
Loading

0 comments on commit 327b057

Please sign in to comment.