diff --git a/src/main/java/carpet/mixins/EndCityFeatureMixin.java b/src/main/java/carpet/mixins/EndCityFeatureMixin.java new file mode 100644 index 00000000..5437d48d --- /dev/null +++ b/src/main/java/carpet/mixins/EndCityFeatureMixin.java @@ -0,0 +1,34 @@ +package carpet.mixins; + +import carpet.CarpetSettings; +import com.google.common.collect.Lists; +import com.mojang.datafixers.Dynamic; +import net.minecraft.entity.EntityType; +import net.minecraft.world.biome.Biome; +import net.minecraft.world.gen.feature.DefaultFeatureConfig; +import net.minecraft.world.gen.feature.EndCityFeature; +import net.minecraft.world.gen.feature.StructureFeature; +import org.spongepowered.asm.mixin.Mixin; + +import java.util.Collections; +import java.util.List; +import java.util.function.Function; + +@Mixin(EndCityFeature.class) +public abstract class EndCityFeatureMixin extends StructureFeature +{ + private static final List spawnList = Lists.newArrayList(new Biome.SpawnEntry(EntityType.SHULKER, 10, 4, 4)); + + public EndCityFeatureMixin(Function, ? extends DefaultFeatureConfig> function_1) + { + super(function_1); + } + + @Override + public List getMonsterSpawns() + { + if (CarpetSettings.b_shulkerSpawningInEndCities) + return spawnList; + return Collections.emptyList(); + } +} diff --git a/src/main/java/carpet/mixins/FloatingIslandsChunkGeneratorMixin.java b/src/main/java/carpet/mixins/FloatingIslandsChunkGeneratorMixin.java new file mode 100644 index 00000000..0fba9b4b --- /dev/null +++ b/src/main/java/carpet/mixins/FloatingIslandsChunkGeneratorMixin.java @@ -0,0 +1,37 @@ +package carpet.mixins; + +import carpet.CarpetSettings; +import net.minecraft.entity.EntityCategory; +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.IWorld; +import net.minecraft.world.biome.Biome; +import net.minecraft.world.biome.source.BiomeSource; +import net.minecraft.world.gen.chunk.FloatingIslandsChunkGenerator; +import net.minecraft.world.gen.chunk.FloatingIslandsChunkGeneratorConfig; +import net.minecraft.world.gen.chunk.SurfaceChunkGenerator; +import net.minecraft.world.gen.feature.Feature; +import org.spongepowered.asm.mixin.Mixin; + +import java.util.List; + +@Mixin(FloatingIslandsChunkGenerator.class) +public abstract class FloatingIslandsChunkGeneratorMixin extends SurfaceChunkGenerator +{ + public FloatingIslandsChunkGeneratorMixin(IWorld iWorld_1, BiomeSource biomeSource_1, int int_1, int int_2, int int_3, FloatingIslandsChunkGeneratorConfig chunkGeneratorConfig_1, boolean boolean_1) + { + super(iWorld_1, biomeSource_1, int_1, int_2, int_3, chunkGeneratorConfig_1, boolean_1); + } + + @Override + public List getEntitySpawnList(EntityCategory entityCategory_1, BlockPos blockPos_1) + { + if (CarpetSettings.b_shulkerSpawningInEndCities && EntityCategory.MONSTER == entityCategory_1) + { + if (Feature.END_CITY.isInsideStructure(this.world, blockPos_1)) + { + return Feature.END_CITY.getMonsterSpawns(); + } + } + return this.world.getBiome(blockPos_1).getEntitySpawnList(entityCategory_1); + } +} diff --git a/src/main/java/carpet/mixins/InfestedBlockMixin.java b/src/main/java/carpet/mixins/InfestedBlockMixin.java new file mode 100644 index 00000000..a9b71f16 --- /dev/null +++ b/src/main/java/carpet/mixins/InfestedBlockMixin.java @@ -0,0 +1,34 @@ +package carpet.mixins; + +import carpet.CarpetSettings; +import net.minecraft.block.Block; +import net.minecraft.block.BlockState; +import net.minecraft.block.Blocks; +import net.minecraft.block.InfestedBlock; +import net.minecraft.item.ItemStack; +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.World; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +@Mixin(InfestedBlock.class) +public abstract class InfestedBlockMixin extends Block +{ + public InfestedBlockMixin(Settings block$Settings_1) + { + super(block$Settings_1); + } + + @Inject(method = "onStacksDropped", at = @At(value = "INVOKE", shift = At.Shift.AFTER, + target = "Lnet/minecraft/entity/mob/SilverfishEntity;playSpawnEffects()V")) + private void onOnStacksDropped(BlockState blockState_1, World world_1, BlockPos blockPos_1, + ItemStack itemStack_1, CallbackInfo ci) + { + if (CarpetSettings.getBool("silverFishDropGravel")) + { + dropStack(world_1, blockPos_1, new ItemStack(Blocks.GRAVEL)); + } + } +} \ No newline at end of file diff --git a/src/main/java/carpet/mixins/PlayerEntityMixin.java b/src/main/java/carpet/mixins/PlayerEntityMixin.java new file mode 100644 index 00000000..812ad91d --- /dev/null +++ b/src/main/java/carpet/mixins/PlayerEntityMixin.java @@ -0,0 +1,23 @@ +package carpet.mixins; + +import carpet.CarpetSettings; +import carpet.helpers.PortalHelper; +import net.minecraft.entity.player.PlayerEntity; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.Constant; +import org.spongepowered.asm.mixin.injection.ModifyConstant; + +@Mixin(PlayerEntity.class) +public abstract class PlayerEntityMixin +{ + @ModifyConstant(method = "getMaxPortalTime", + constant = @Constant(intValue = 1)) + private int addFillUpdatesInt(int original) { + if (CarpetSettings.getBool("portalCreativeDelay")) + if (PortalHelper.player_holds_obsidian((PlayerEntity) (Object)this)) + return 72000; + else + return 80; + return original; + } +} diff --git a/src/main/java/carpet/mixins/PlayerManagerMixin.java b/src/main/java/carpet/mixins/PlayerManagerMixin.java new file mode 100644 index 00000000..1d1dfa6b --- /dev/null +++ b/src/main/java/carpet/mixins/PlayerManagerMixin.java @@ -0,0 +1,79 @@ +package carpet.mixins; + +import com.mojang.authlib.GameProfile; +import net.minecraft.nbt.CompoundTag; +import net.minecraft.network.ClientConnection; +import net.minecraft.network.chat.TranslatableComponent; +import net.minecraft.server.MinecraftServer; +import net.minecraft.server.PlayerManager; +import net.minecraft.server.network.ServerPlayNetworkHandler; +import net.minecraft.server.network.ServerPlayerEntity; +import org.spongepowered.asm.mixin.Final; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.Redirect; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; +import org.spongepowered.asm.mixin.injection.callback.LocalCapture; +import carpet.patches.NetHandlerPlayServerFake; +import carpet.patches.EntityPlayerMPFake; + +import java.util.Iterator; +import java.util.List; +import java.util.UUID; + +@Mixin(PlayerManager.class) +public abstract class PlayerManagerMixin +{ + @Shadow + @Final + private MinecraftServer server; + + @Inject(method = "loadPlayerData", at = @At(value = "RETURN", shift = At.Shift.BEFORE)) + private void fixStartingPos(ServerPlayerEntity serverPlayerEntity_1, CallbackInfoReturnable cir) + { + if (serverPlayerEntity_1 instanceof EntityPlayerMPFake) + { + ((EntityPlayerMPFake) serverPlayerEntity_1).fixStartingPosition.run(); + } + } + + @Redirect(method = "onPlayerConnect", at = @At(value = "NEW", target = "net/minecraft/server/network/ServerPlayNetworkHandler")) + private ServerPlayNetworkHandler replaceNetworkHandler(MinecraftServer server, ClientConnection clientConnection, ServerPlayerEntity playerIn) + { + boolean isServerPlayerEntity = playerIn instanceof EntityPlayerMPFake; + if (isServerPlayerEntity) + { + return new NetHandlerPlayServerFake(this.server, clientConnection, playerIn); + } + else + { + return new ServerPlayNetworkHandler(this.server, clientConnection, playerIn); + } + } + + @Redirect(method = "createPlayer", at = @At(value = "INVOKE", target = "Ljava/util/Iterator;hasNext()Z")) + private boolean cancelWhileLoop(Iterator iterator) + { + return false; + } + + @Inject(method = "createPlayer", at = @At(value = "INVOKE", shift = At.Shift.BEFORE, + target = "Ljava/util/Iterator;hasNext()Z"), locals = LocalCapture.CAPTURE_FAILHARD) + private void newWhileLoop(GameProfile gameProfile_1, CallbackInfoReturnable cir, UUID uUID_1, + List list_1, Iterator var5) + { + while (var5.hasNext()) + { + ServerPlayerEntity serverPlayerEntity_3 = (ServerPlayerEntity) var5.next(); + if(serverPlayerEntity_3 instanceof EntityPlayerMPFake) + { + serverPlayerEntity_3.kill(); + continue; + } + serverPlayerEntity_3.networkHandler.disconnect(new TranslatableComponent("multiplayer.disconnect.duplicate_login", new Object[0])); + } + } + +} \ No newline at end of file diff --git a/src/main/java/carpet/mixins/PrimedTntEntityMixin.java b/src/main/java/carpet/mixins/PrimedTntEntityMixin.java new file mode 100644 index 00000000..f91fd956 --- /dev/null +++ b/src/main/java/carpet/mixins/PrimedTntEntityMixin.java @@ -0,0 +1,44 @@ +package carpet.mixins; + +import net.minecraft.entity.Entity; +import net.minecraft.entity.EntityType; +import net.minecraft.entity.LivingEntity; +import net.minecraft.entity.PrimedTntEntity; +import net.minecraft.world.World; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; +import carpet.logging.LoggerRegistry; +import carpet.logging.logHelpers.TNTLogHelper; + +@Mixin(PrimedTntEntity.class) +public abstract class PrimedTntEntityMixin extends Entity +{ + private TNTLogHelper logHelper = null; + + public PrimedTntEntityMixin(EntityType entityType_1, World world_1) + { + super(entityType_1, world_1); + } + + @Inject(method = "(Lnet/minecraft/world/World;DDDLnet/minecraft/entity/LivingEntity;)V", + at = @At(value = "RETURN")) + private void initTNTLogger(World world_1, double double_1, double double_2, double double_3, + LivingEntity livingEntity_1, CallbackInfo ci) + { + double double_4 = world_1.random.nextDouble() * 6.2831854820251465D; + if (LoggerRegistry.__tnt) + { + logHelper = new TNTLogHelper(); + logHelper.onPrimed(double_1, double_2, double_3, (float)double_4); + } + } + + @Inject(method = "explode", at = @At(value = "HEAD")) + private void onExplode(CallbackInfo ci) + { + if (LoggerRegistry.__tnt && logHelper != null) + logHelper.onExploded(x, y, z); + } +} \ No newline at end of file diff --git a/src/main/java/carpet/mixins/SpawnRestrictionMixin.java b/src/main/java/carpet/mixins/SpawnRestrictionMixin.java new file mode 100644 index 00000000..bf8a86a7 --- /dev/null +++ b/src/main/java/carpet/mixins/SpawnRestrictionMixin.java @@ -0,0 +1,18 @@ +package carpet.mixins; + +import net.minecraft.entity.EntityType; +import net.minecraft.entity.SpawnRestriction; +import net.minecraft.world.Heightmap; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; + +@Mixin(SpawnRestriction.class) +public abstract class SpawnRestrictionMixin +{ + @Shadow + private static void register(EntityType a, SpawnRestriction.Location b, Heightmap.Type c) { } + + static { + register(EntityType.SHULKER, SpawnRestriction.Location.ON_GROUND, Heightmap.Type.MOTION_BLOCKING_NO_LEAVES); + } +} \ No newline at end of file diff --git a/src/main/resources/carpet.mixins.json b/src/main/resources/carpet.mixins.json index 661a9146..c9262b34 100644 --- a/src/main/resources/carpet.mixins.json +++ b/src/main/resources/carpet.mixins.json @@ -29,6 +29,7 @@ "ExperienceOrbEntityMixin", "PlayerActionC2SPacketMixin", "ServerPlayerEntityMixin", + "PlayerManagerMixin", "ServerChunkManagerMixin", "SpawnHelperMixin", @@ -38,7 +39,16 @@ "ClientConnectionMixin", "ItemEntityMixin", "TntBlockMixin", - "ExplosionMixin" + "ExplosionMixin", + + "PrimedTNTEntityMixin", + + "FloatingIslandsChunkGeneratorMixin", + "EndCityFeatureMixin", + "SpawnRestrictionMixin", + + "InfestedBlockMixin", + "PlayerEntityMixin" ], "client": [ "DebugHudMixin",