From 59a8c4c86911a99b664d7809254aabdc3ba89758 Mon Sep 17 00:00:00 2001 From: TheBrokenRail Date: Thu, 19 Mar 2020 17:33:44 -0400 Subject: [PATCH] 1.0.1 Update Mappings Add Throwable Spawn Eggs --- CHANGELOG.md | 4 ++ README.md | 1 + gradle.properties | 6 +- .../slightlyvanilla/ModConfig.java | 1 + .../slightlyvanilla/SlightlyVanilla.java | 8 +++ .../client/SlightlyVanillaClient.java | 2 + .../entity/SlimeballEntity.java | 4 +- .../entity/SpawnEggEntity.java | 69 +++++++++++++++++++ .../mixin/MixinClientPlayNetworkHandler.java | 3 + .../slightlyvanilla/mixin/MixinItem.java | 1 + .../mixin/MixinPlayerEntity.java | 1 + .../mixin/MixinRespawnAnchorBlock.java | 1 + .../mixin/MixinSpawnEggItem.java | 33 +++++++++ .../assets/slightlyvanilla/lang/en_us.json | 4 +- .../resources/slightlyvanilla.mixins.json | 3 +- 15 files changed, 134 insertions(+), 7 deletions(-) create mode 100644 src/main/java/com/thebrokenrail/slightlyvanilla/entity/SpawnEggEntity.java create mode 100644 src/main/java/com/thebrokenrail/slightlyvanilla/mixin/MixinSpawnEggItem.java diff --git a/CHANGELOG.md b/CHANGELOG.md index 141f1e4..8e28982 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,8 @@ # Changelog +**1.0.1** +* Update Mappings +* Add Throwable Spawn Eggs + **1.0** * Initial Release diff --git a/README.md b/README.md index 81b9d39..3902354 100644 --- a/README.md +++ b/README.md @@ -8,6 +8,7 @@ Suggest more tweaks in the issue tracker! * Use Respawn Anchor in Any Dimension * Instantly Kill In Creative Mode * Throwable Slimeballs +* Throwable Spawn Eggs ## Changelog [View Changelog](CHANGELOG.md) diff --git a/gradle.properties b/gradle.properties index 946c3bd..4bf903f 100644 --- a/gradle.properties +++ b/gradle.properties @@ -6,11 +6,11 @@ org.gradle.jvmargs = -Xmx1G minecraft_version = 20w12a curseforge_id = 368420 simple_minecraft_version = 1.16-Snapshot - yarn_build = 12 - fabric_loader_version = 0.7.8+build.187 + yarn_build = 14 + fabric_loader_version = 0.7.8+build.189 # Mod Properties - mod_version = 1.0.0 + mod_version = 1.0.1 maven_group = com.thebrokenrail archives_base_name = slightlyvanilla diff --git a/src/main/java/com/thebrokenrail/slightlyvanilla/ModConfig.java b/src/main/java/com/thebrokenrail/slightlyvanilla/ModConfig.java index c9798ee..5010fa5 100644 --- a/src/main/java/com/thebrokenrail/slightlyvanilla/ModConfig.java +++ b/src/main/java/com/thebrokenrail/slightlyvanilla/ModConfig.java @@ -8,4 +8,5 @@ public class ModConfig implements ConfigData { public boolean useRespawnAnchorInAnyDimension = true; public boolean instantlyKillInCreative = true; public boolean throwableSlimeballs = true; + public boolean throwableSpawnEggs = true; } diff --git a/src/main/java/com/thebrokenrail/slightlyvanilla/SlightlyVanilla.java b/src/main/java/com/thebrokenrail/slightlyvanilla/SlightlyVanilla.java index 13f89de..41a9c96 100644 --- a/src/main/java/com/thebrokenrail/slightlyvanilla/SlightlyVanilla.java +++ b/src/main/java/com/thebrokenrail/slightlyvanilla/SlightlyVanilla.java @@ -1,6 +1,7 @@ package com.thebrokenrail.slightlyvanilla; import com.thebrokenrail.slightlyvanilla.entity.SlimeballEntity; +import com.thebrokenrail.slightlyvanilla.entity.SpawnEggEntity; import me.sargunvohra.mcmods.autoconfig1u.AutoConfig; import me.sargunvohra.mcmods.autoconfig1u.serializer.GsonConfigSerializer; import net.fabricmc.api.ModInitializer; @@ -8,11 +9,14 @@ import net.fabricmc.fabric.api.entity.FabricEntityTypeBuilder; import net.minecraft.entity.EntityCategory; import net.minecraft.entity.EntityDimensions; import net.minecraft.entity.EntityType; +import net.minecraft.util.Identifier; +import net.minecraft.util.registry.Registry; public class SlightlyVanilla implements ModInitializer { public static final String NAMESPACE = "slightlyvanilla"; public static EntityType SLIMEBALL_ENTITY; + public static EntityType SPAWN_EGG_ENTITY; public static ModConfig getConfig() { return AutoConfig.getConfigHolder(ModConfig.class).getConfig(); @@ -23,5 +27,9 @@ public class SlightlyVanilla implements ModInitializer { AutoConfig.register(ModConfig.class, GsonConfigSerializer::new); SLIMEBALL_ENTITY = FabricEntityTypeBuilder.create(EntityCategory.MISC, (EntityType.EntityFactory) SlimeballEntity::new).size(EntityDimensions.fixed(0.25f, 0.25f)).build(); + SPAWN_EGG_ENTITY = FabricEntityTypeBuilder.create(EntityCategory.MISC, (EntityType.EntityFactory) SpawnEggEntity::new).size(EntityDimensions.fixed(0.25f, 0.25f)).build(); + + Registry.register(Registry.ENTITY_TYPE, new Identifier(NAMESPACE, "slimeball"), SLIMEBALL_ENTITY); + Registry.register(Registry.ENTITY_TYPE, new Identifier(NAMESPACE, "spawn_egg"), SPAWN_EGG_ENTITY); } } diff --git a/src/main/java/com/thebrokenrail/slightlyvanilla/client/SlightlyVanillaClient.java b/src/main/java/com/thebrokenrail/slightlyvanilla/client/SlightlyVanillaClient.java index 666daf6..e028002 100644 --- a/src/main/java/com/thebrokenrail/slightlyvanilla/client/SlightlyVanillaClient.java +++ b/src/main/java/com/thebrokenrail/slightlyvanilla/client/SlightlyVanillaClient.java @@ -3,6 +3,7 @@ package com.thebrokenrail.slightlyvanilla.client; import com.thebrokenrail.slightlyvanilla.SlightlyVanilla; import com.thebrokenrail.slightlyvanilla.ModConfig; import com.thebrokenrail.slightlyvanilla.entity.SlimeballEntity; +import com.thebrokenrail.slightlyvanilla.entity.SpawnEggEntity; import io.github.prospector.modmenu.api.ConfigScreenFactory; import io.github.prospector.modmenu.api.ModMenuApi; import me.sargunvohra.mcmods.autoconfig1u.AutoConfig; @@ -15,6 +16,7 @@ public class SlightlyVanillaClient implements ClientModInitializer, ModMenuApi { @Override public void onInitializeClient() { EntityRendererRegistry.INSTANCE.register(SlightlyVanilla.SLIMEBALL_ENTITY, (entityRenderDispatcher, context) -> new FlyingItemEntityRenderer(entityRenderDispatcher, context.getItemRenderer())); + EntityRendererRegistry.INSTANCE.register(SlightlyVanilla.SPAWN_EGG_ENTITY, (entityRenderDispatcher, context) -> new FlyingItemEntityRenderer(entityRenderDispatcher, context.getItemRenderer())); } @Override diff --git a/src/main/java/com/thebrokenrail/slightlyvanilla/entity/SlimeballEntity.java b/src/main/java/com/thebrokenrail/slightlyvanilla/entity/SlimeballEntity.java index aa9a44f..3026607 100644 --- a/src/main/java/com/thebrokenrail/slightlyvanilla/entity/SlimeballEntity.java +++ b/src/main/java/com/thebrokenrail/slightlyvanilla/entity/SlimeballEntity.java @@ -9,6 +9,7 @@ import net.minecraft.entity.projectile.thrown.ThrownItemEntity; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.item.Items; +import net.minecraft.item.SpawnEggItem; import net.minecraft.network.Packet; import net.minecraft.network.packet.s2c.play.EntitySpawnS2CPacket; import net.minecraft.particle.ItemStackParticleEffect; @@ -36,8 +37,7 @@ public class SlimeballEntity extends ThrownItemEntity { @Environment(EnvType.CLIENT) private ParticleEffect getParticleParameters() { - ItemStack itemStack = getItem(); - return itemStack.isEmpty() ? ParticleTypes.ITEM_SLIME : new ItemStackParticleEffect(ParticleTypes.ITEM, itemStack); + return ParticleTypes.ITEM_SLIME; } @Environment(EnvType.CLIENT) diff --git a/src/main/java/com/thebrokenrail/slightlyvanilla/entity/SpawnEggEntity.java b/src/main/java/com/thebrokenrail/slightlyvanilla/entity/SpawnEggEntity.java new file mode 100644 index 0000000..8454412 --- /dev/null +++ b/src/main/java/com/thebrokenrail/slightlyvanilla/entity/SpawnEggEntity.java @@ -0,0 +1,69 @@ +package com.thebrokenrail.slightlyvanilla.entity; + +import com.thebrokenrail.slightlyvanilla.SlightlyVanilla; +import net.fabricmc.api.EnvType; +import net.fabricmc.api.Environment; +import net.minecraft.entity.EntityType; +import net.minecraft.entity.LivingEntity; +import net.minecraft.entity.SpawnType; +import net.minecraft.entity.projectile.thrown.ThrownItemEntity; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.item.Items; +import net.minecraft.item.SpawnEggItem; +import net.minecraft.network.Packet; +import net.minecraft.network.packet.s2c.play.EntitySpawnS2CPacket; +import net.minecraft.particle.ItemStackParticleEffect; +import net.minecraft.particle.ParticleEffect; +import net.minecraft.particle.ParticleTypes; +import net.minecraft.util.hit.HitResult; +import net.minecraft.world.World; + +public class SpawnEggEntity extends ThrownItemEntity { + public SpawnEggEntity(EntityType entityType, World world) { + super(entityType, world); + } + + public SpawnEggEntity(World world, LivingEntity owner) { + super(SlightlyVanilla.SPAWN_EGG_ENTITY, owner, world); + } + + public SpawnEggEntity(World world, double x, double y, double z) { + super(SlightlyVanilla.SPAWN_EGG_ENTITY, x, y, z, world); + } + + protected Item getDefaultItem() { + return Items.PIG_SPAWN_EGG; + } + + @Environment(EnvType.CLIENT) + private ParticleEffect getParticleParameters() { + return new ItemStackParticleEffect(ParticleTypes.ITEM, getStack()); + } + + @Environment(EnvType.CLIENT) + public void handleStatus(byte status) { + if (status == 3) { + ParticleEffect particleEffect = getParticleParameters(); + + for (int i = 0; i < 8; ++i) { + world.addParticle(particleEffect, getX(), getY(), getZ(), 0.0D, 0.0D, 0.0D); + } + } + } + + protected void onCollision(HitResult hitResult) { + super.onCollision(hitResult); + if (!world.isClient()) { + world.sendEntityStatus(this, (byte) 3); + EntityType entityType = ((SpawnEggItem) getStack().getItem()).getEntityType(getStack().getTag()); + entityType.spawnFromItemStack(world, getItem(), null, getBlockPos(), SpawnType.SPAWN_EGG, false, false); + remove(); + } + } + + @Override + public Packet createSpawnPacket() { + return new EntitySpawnS2CPacket(this); + } +} diff --git a/src/main/java/com/thebrokenrail/slightlyvanilla/mixin/MixinClientPlayNetworkHandler.java b/src/main/java/com/thebrokenrail/slightlyvanilla/mixin/MixinClientPlayNetworkHandler.java index e8516d4..d9deb4b 100644 --- a/src/main/java/com/thebrokenrail/slightlyvanilla/mixin/MixinClientPlayNetworkHandler.java +++ b/src/main/java/com/thebrokenrail/slightlyvanilla/mixin/MixinClientPlayNetworkHandler.java @@ -2,6 +2,7 @@ package com.thebrokenrail.slightlyvanilla.mixin; import com.thebrokenrail.slightlyvanilla.SlightlyVanilla; import com.thebrokenrail.slightlyvanilla.entity.SlimeballEntity; +import com.thebrokenrail.slightlyvanilla.entity.SpawnEggEntity; import net.minecraft.client.network.ClientPlayNetworkHandler; import net.minecraft.client.world.ClientWorld; import net.minecraft.entity.Entity; @@ -26,6 +27,8 @@ public class MixinClientPlayNetworkHandler { if (entityType == SlightlyVanilla.SLIMEBALL_ENTITY) { entity = new SlimeballEntity(world, packet.getX(), packet.getY(), packet.getZ()); + } else if (entityType == SlightlyVanilla.SPAWN_EGG_ENTITY) { + entity = new SpawnEggEntity(world, packet.getX(), packet.getY(), packet.getZ()); } if (entity != null) { diff --git a/src/main/java/com/thebrokenrail/slightlyvanilla/mixin/MixinItem.java b/src/main/java/com/thebrokenrail/slightlyvanilla/mixin/MixinItem.java index 072dff2..c8a5760 100644 --- a/src/main/java/com/thebrokenrail/slightlyvanilla/mixin/MixinItem.java +++ b/src/main/java/com/thebrokenrail/slightlyvanilla/mixin/MixinItem.java @@ -15,6 +15,7 @@ import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; +@SuppressWarnings("unused") @Mixin(Item.class) public class MixinItem { @Inject(at = @At("HEAD"), method = "use", cancellable = true) diff --git a/src/main/java/com/thebrokenrail/slightlyvanilla/mixin/MixinPlayerEntity.java b/src/main/java/com/thebrokenrail/slightlyvanilla/mixin/MixinPlayerEntity.java index 8a1809e..a1cb1ea 100644 --- a/src/main/java/com/thebrokenrail/slightlyvanilla/mixin/MixinPlayerEntity.java +++ b/src/main/java/com/thebrokenrail/slightlyvanilla/mixin/MixinPlayerEntity.java @@ -10,6 +10,7 @@ import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; +@SuppressWarnings("unused") @Mixin(PlayerEntity.class) public class MixinPlayerEntity { @Inject(at = @At("HEAD"), method = "attack", cancellable = true) diff --git a/src/main/java/com/thebrokenrail/slightlyvanilla/mixin/MixinRespawnAnchorBlock.java b/src/main/java/com/thebrokenrail/slightlyvanilla/mixin/MixinRespawnAnchorBlock.java index 4cf2283..9c331d5 100644 --- a/src/main/java/com/thebrokenrail/slightlyvanilla/mixin/MixinRespawnAnchorBlock.java +++ b/src/main/java/com/thebrokenrail/slightlyvanilla/mixin/MixinRespawnAnchorBlock.java @@ -8,6 +8,7 @@ import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Redirect; +@SuppressWarnings("unused") @Mixin(RespawnAnchorBlock.class) public class MixinRespawnAnchorBlock { @Redirect(at = @At(value = "INVOKE", target = "Lnet/minecraft/world/dimension/Dimension;getType()Lnet/minecraft/world/dimension/DimensionType;", ordinal = 0), method = "onUse") diff --git a/src/main/java/com/thebrokenrail/slightlyvanilla/mixin/MixinSpawnEggItem.java b/src/main/java/com/thebrokenrail/slightlyvanilla/mixin/MixinSpawnEggItem.java new file mode 100644 index 0000000..9efe4e8 --- /dev/null +++ b/src/main/java/com/thebrokenrail/slightlyvanilla/mixin/MixinSpawnEggItem.java @@ -0,0 +1,33 @@ +package com.thebrokenrail.slightlyvanilla.mixin; + +import com.thebrokenrail.slightlyvanilla.SlightlyVanilla; +import com.thebrokenrail.slightlyvanilla.entity.SpawnEggEntity; +import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.item.ItemStack; +import net.minecraft.item.SpawnEggItem; +import net.minecraft.util.ActionResult; +import net.minecraft.util.Hand; +import net.minecraft.util.TypedActionResult; +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.CallbackInfoReturnable; + +@SuppressWarnings("unused") +@Mixin(SpawnEggItem.class) +public class MixinSpawnEggItem { + @Inject(at = @At("RETURN"), method = "use", cancellable = true) + public void use(World world, PlayerEntity user, Hand hand, CallbackInfoReturnable> info) { + if (SlightlyVanilla.getConfig().throwableSpawnEggs && info.getReturnValue().getResult() == ActionResult.PASS) { + ItemStack stack = user.getStackInHand(hand); + if (!world.isClient()) { + SpawnEggEntity entity = new SpawnEggEntity(world, user); + entity.setItem(stack); + entity.setProperties(user, user.pitch, user.yaw, 0.0f, 1.5f, 1.0f); + world.spawnEntity(entity); + } + info.setReturnValue(new TypedActionResult<>(ActionResult.SUCCESS, stack)); + } + } +} diff --git a/src/main/resources/assets/slightlyvanilla/lang/en_us.json b/src/main/resources/assets/slightlyvanilla/lang/en_us.json index 4fcf05c..3c74eb5 100644 --- a/src/main/resources/assets/slightlyvanilla/lang/en_us.json +++ b/src/main/resources/assets/slightlyvanilla/lang/en_us.json @@ -2,5 +2,7 @@ "text.autoconfig.slightlyvanilla.title": "SlightlyVanilla Tweaks", "text.autoconfig.slightlyvanilla.option.useRespawnAnchorInAnyDimension": "Use Respawn Anchor In Any Dimension", "text.autoconfig.slightlyvanilla.option.instantlyKillInCreative": "Instantly Kill In Creative Mode", - "text.autoconfig.slightlyvanilla.option.throwableSlimeballs": "Throwable Slimeballs" + "text.autoconfig.slightlyvanilla.option.throwableSlimeballs": "Throwable Slimeballs", + "entity.slightlyvanilla.slimeball": "Slimeball", + "entity.slightlyvanilla.spawn_egg": "Spawn Egg" } \ No newline at end of file diff --git a/src/main/resources/slightlyvanilla.mixins.json b/src/main/resources/slightlyvanilla.mixins.json index 10aff57..bcc16ef 100644 --- a/src/main/resources/slightlyvanilla.mixins.json +++ b/src/main/resources/slightlyvanilla.mixins.json @@ -8,7 +8,8 @@ "mixins": [ "MixinRespawnAnchorBlock", "MixinPlayerEntity", - "MixinItem" + "MixinItem", + "MixinSpawnEggItem" ], "injectors": { "defaultRequire": 1