diff --git a/src/main/java/com/minelittlepony/unicopia/CustomStatusEffect.java b/src/main/java/com/minelittlepony/unicopia/CustomStatusEffect.java new file mode 100644 index 00000000..5dcac8f7 --- /dev/null +++ b/src/main/java/com/minelittlepony/unicopia/CustomStatusEffect.java @@ -0,0 +1,98 @@ +package com.minelittlepony.unicopia; + +import javax.annotation.Nonnull; +import javax.annotation.Nullable; + +import net.minecraft.entity.Entity; +import net.minecraft.entity.LivingEntity; +import net.minecraft.entity.effect.StatusEffect; +import net.minecraft.entity.effect.StatusEffectType; +import net.minecraft.util.Identifier; +import net.minecraft.util.registry.Registry; + +public class CustomStatusEffect extends StatusEffect { + + private int tickDelay = 40; + + @Nonnull + private DirectEffect direct = DirectEffect.NONE; + + @Nonnull + private IndirectEffect indirect = IndirectEffect.NONE; + + public CustomStatusEffect(Identifier id, StatusEffectType type, int color) { + super(type, color); + + Registry.register(Registry.STATUS_EFFECT, id, this); + } + + public CustomStatusEffect setSilent() { + return this; + } + + public CustomStatusEffect direct(@Nonnull DirectEffect applicator) { + this.direct = applicator; + + return this; + } + + public CustomStatusEffect indirect(@Nonnull IndirectEffect applicator) { + this.indirect = applicator; + + return this; + } + + + public CustomStatusEffect setTickDelay(int delay) { + tickDelay = delay; + + return this; + } + + public CustomStatusEffect setEffectiveness(double effectiveness) { + + return this; + } + + @Override + public void applyUpdateEffect(LivingEntity target, int amplifier) { + direct.perform(this, target, amplifier); + } + + @Override + public void applyInstantEffect(@Nullable Entity source, @Nullable Entity attacker, LivingEntity target, int amplifier, double distance) { + indirect.perform(this, source, attacker, target, amplifier, distance); + } + + @Override + public boolean isInstant() { + return tickDelay > 0; + } + + @Override + public boolean canApplyUpdateEffect(int duration, int amplifier) { + if (!isInstant()) { + int i = tickDelay >> amplifier; + + if (i > 0) { + return duration % i == 0; + } + } + + return duration > 0; + } + + @FunctionalInterface + public interface DirectEffect { + DirectEffect NONE = (p, e, i) -> {}; + + void perform(StatusEffect effect, LivingEntity target, int amplifier); + } + + @FunctionalInterface + public interface IndirectEffect { + IndirectEffect NONE = (p, s, a, t, A, d) -> {}; + + void perform(StatusEffect effect, @Nullable Entity source, @Nullable Entity attacker, LivingEntity target, int amplifier, double distance); + } +} diff --git a/src/main/java/com/minelittlepony/unicopia/InteractionManager.java b/src/main/java/com/minelittlepony/unicopia/InteractionManager.java new file mode 100644 index 00000000..9604bc61 --- /dev/null +++ b/src/main/java/com/minelittlepony/unicopia/InteractionManager.java @@ -0,0 +1,51 @@ +package com.minelittlepony.unicopia; + +import javax.annotation.Nonnull; +import javax.annotation.Nullable; + +import com.minelittlepony.unicopia.client.ClientInteractionManager; +import com.minelittlepony.unicopia.entity.capabilities.IPlayer; +import com.mojang.authlib.GameProfile; + +import net.minecraft.entity.Entity; +import net.minecraft.entity.player.PlayerEntity; + +public interface InteractionManager { + + static InteractionManager instance() { + if (Unicopia.interactionManager == null) { + if (ServerInteractionManager.isClientSide()) { + Unicopia.interactionManager = new ClientInteractionManager(); + } else { + Unicopia.interactionManager = new ServerInteractionManager(); + } + } + + return Unicopia.interactionManager; + } + + @Nullable + PlayerEntity getClientPlayer(); + + @Nullable + default IPlayer getIPlayer() { + return SpeciesList.instance().getPlayer(getClientPlayer()); + } + + boolean isClientPlayer(@Nullable PlayerEntity player); + + int getViewMode(); + + /** + * Side-independent method to create a new player. + * + * Returns an implementation of PlayerEntity appropriate to the side being called on. + */ + @Nonnull + PlayerEntity createPlayer(Entity observer, GameProfile profile); + + void postRenderEntity(Entity entity); + + boolean renderEntity(Entity entity, float renderPartialTicks); + +} diff --git a/src/main/java/com/minelittlepony/unicopia/Race.java b/src/main/java/com/minelittlepony/unicopia/Race.java index f28f3d96..ffbf1524 100644 --- a/src/main/java/com/minelittlepony/unicopia/Race.java +++ b/src/main/java/com/minelittlepony/unicopia/Race.java @@ -34,6 +34,10 @@ public enum Race { this.earth = earth; } + public boolean isUsable() { + return !isDefault(); + } + public boolean isDefault() { return this == HUMAN; } diff --git a/src/main/java/com/minelittlepony/unicopia/ServerInteractionManager.java b/src/main/java/com/minelittlepony/unicopia/ServerInteractionManager.java new file mode 100644 index 00000000..80767077 --- /dev/null +++ b/src/main/java/com/minelittlepony/unicopia/ServerInteractionManager.java @@ -0,0 +1,61 @@ +package com.minelittlepony.unicopia; + +import javax.annotation.Nonnull; +import javax.annotation.Nullable; + +import com.minelittlepony.util.dummy.DummyPlayerEntity; +import com.minelittlepony.util.dummy.DummyServerPlayerEntity; +import com.mojang.authlib.GameProfile; + +import net.minecraft.entity.Entity; +import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.server.world.ServerWorld; + +public class ServerInteractionManager implements InteractionManager { + + @Deprecated + public static boolean isClientSide() { + return false; + } + + @Override + @Nullable + public PlayerEntity getClientPlayer() { + return null; + } + + @Override + public boolean isClientPlayer(@Nullable PlayerEntity player) { + return false; + } + + @Override + public int getViewMode() { + return 0; + } + + /** + * Side-independent method to create a new player. + * + * Returns an implementation of PlayerEntity appropriate to the side being called on. + */ + @Override + @Nonnull + public PlayerEntity createPlayer(Entity observer, GameProfile profile) { + if (observer.world instanceof ServerWorld) { + return new DummyServerPlayerEntity((ServerWorld)observer.world, profile); + } + return new DummyPlayerEntity(observer.world, profile); + } + + @Override + public void postRenderEntity(Entity entity) { + + } + + @Override + public boolean renderEntity(Entity entity, float renderPartialTicks) { + return false; + } + +} diff --git a/src/main/java/com/minelittlepony/unicopia/SpeciesList.java b/src/main/java/com/minelittlepony/unicopia/SpeciesList.java index ff9f26dc..0dca8303 100644 --- a/src/main/java/com/minelittlepony/unicopia/SpeciesList.java +++ b/src/main/java/com/minelittlepony/unicopia/SpeciesList.java @@ -1,8 +1,6 @@ package com.minelittlepony.unicopia; import java.util.Optional; -import java.util.UUID; - import javax.annotation.Nullable; import com.minelittlepony.unicopia.Config; @@ -62,11 +60,6 @@ public class SpeciesList { return this.getEntity(player); } - @Nullable - public IPlayer getPlayer(UUID playerId) { - return getPlayer(IPlayer.fromServer(playerId)); - } - @Nullable public T getEntity(Entity entity) { return this.getForEntity(entity) diff --git a/src/main/java/com/minelittlepony/unicopia/UBlocks.java b/src/main/java/com/minelittlepony/unicopia/UBlocks.java index ad07bef3..6e57e4f3 100644 --- a/src/main/java/com/minelittlepony/unicopia/UBlocks.java +++ b/src/main/java/com/minelittlepony/unicopia/UBlocks.java @@ -14,67 +14,67 @@ import com.minelittlepony.unicopia.block.HiveWallBlock; import com.minelittlepony.unicopia.block.IColourful; import com.minelittlepony.unicopia.block.SlimeLayerBlock; import com.minelittlepony.unicopia.block.StickBlock; -import com.minelittlepony.unicopia.block.BlockCloudAnvil; -import com.minelittlepony.unicopia.block.BlockCloudBanister; -import com.minelittlepony.unicopia.block.BlockCloudSlab; +import com.minelittlepony.unicopia.block.CloudAnvilBlock; +import com.minelittlepony.unicopia.block.CloudSlabBlock; +import com.minelittlepony.unicopia.block.CloudBanisterBlock; import com.minelittlepony.unicopia.block.BlockCloudStairs; -import com.minelittlepony.unicopia.block.BlockDutchDoor; +import com.minelittlepony.unicopia.block.DutchDoorBlock; import com.minelittlepony.unicopia.block.SugarBlock; import com.minelittlepony.unicopia.block.UPot; -import com.minelittlepony.unicopia.block.USapling; +import com.minelittlepony.unicopia.item.AppleItem; +import com.minelittlepony.unicopia.world.structure.CustomSaplingGenerator; import com.minelittlepony.unicopia.block.BlockTomatoPlant; import com.minelittlepony.unicopia.block.BlockCloudDoor; -import com.minelittlepony.unicopia.block.BlockDiamondDoor; +import com.minelittlepony.unicopia.block.DiamondDoorBlock; import com.minelittlepony.unicopia.block.BlockCloudFarm; -import com.minelittlepony.unicopia.block.BlockCloudFence; -import com.minelittlepony.unicopia.block.BlockCloud; +import com.minelittlepony.unicopia.block.CloudFenceBlock; +import com.minelittlepony.unicopia.block.CloudBlock; +import net.fabricmc.fabric.api.block.FabricBlockSettings; import net.minecraft.block.Block; import net.minecraft.block.BlockState; import net.minecraft.block.Blocks; import net.minecraft.block.Material; +import net.minecraft.block.SaplingBlock; import net.minecraft.client.color.block.BlockColors; import net.minecraft.client.color.item.ItemColors; import net.minecraft.client.color.world.BiomeColors; import net.minecraft.client.color.world.GrassColors; import net.minecraft.item.BlockItem; import net.minecraft.item.ItemStack; +import net.minecraft.sound.BlockSoundGroup; import net.minecraft.util.Identifier; import net.minecraft.util.registry.Registry; public class UBlocks { - public static final BlockCloud normal_cloud = register(new BlockCloud(UMaterials.cloud, CloudType.NORMAL), "cloud_block"); - public static final BlockCloud enchanted_cloud = register(new BlockCloud(UMaterials.cloud, CloudType.ENCHANTED), "enchanted_cloud_block"); - public static final BlockCloud packed_cloud = register(new BlockCloud(UMaterials.cloud, CloudType.PACKED), "packed_cloud_block"); + public static final CloudBlock normal_cloud = register(new CloudBlock(UMaterials.cloud, CloudType.NORMAL), "cloud_block"); + public static final CloudBlock enchanted_cloud = register(new CloudBlock(UMaterials.cloud, CloudType.ENCHANTED), "enchanted_cloud_block"); + public static final CloudBlock packed_cloud = register(new CloudBlock(UMaterials.cloud, CloudType.PACKED), "packed_cloud_block"); - public static final BlockCloudStairs cloud_stairs = register(new BlockCloudStairs(normal_cloud.getDefaultState(), Unicopia.MODID, "cloud_stairs")); + public static final BlockCloudStairs cloud_stairs = register(new BlockCloudStairs(normal_cloud.getDefaultState()), "cloud_stairs"); - public static final BlockCloudSlab.Single cloud_slab = register(new BlockCloudSlab.Single<>(normal_cloud, UMaterials.cloud, Unicopia.MODID, "cloud_slab")); - public static final BlockCloudSlab.Single enchanted_cloud_slab = register(new BlockCloudSlab.Single<>(enchanted_cloud, UMaterials.cloud, Unicopia.MODID, "enchanted_cloud_slab")); - public static final BlockCloudSlab.Single packed_cloud_slab = register(new BlockCloudSlab.Single<>(enchanted_cloud, UMaterials.cloud, Unicopia.MODID, "packed_cloud_slab")); + public static final CloudSlabBlock cloud_slab = register(new CloudSlabBlock<>(normal_cloud, UMaterials.cloud), "cloud_slab"); + public static final CloudSlabBlock enchanted_cloud_slab = register(new CloudSlabBlock<>(enchanted_cloud, UMaterials.cloud), "enchanted_cloud_slab"); + public static final CloudSlabBlock packed_cloud_slab = register(new CloudSlabBlock<>(enchanted_cloud, UMaterials.cloud), "packed_cloud_slab"); - public static final BlockCloudDoor mist_door = register(new BlockCloudDoor(UMaterials.cloud, Unicopia.MODID, "mist_door", () -> UItems.mist_door)); - public static final Block library_door = register(new BlockDutchDoor(Material.WOOD, Unicopia.MODID, "library_door", () -> UItems.library_door) - .setSoundType(SoundType.WOOD) - .setHardness(3)); - public static final Block bakery_door = register(new BlockDutchDoor(Material.WOOD, Unicopia.MODID, "bakery_door", () -> UItems.bakery_door) - .setSoundType(SoundType.WOOD) - .setHardness(3)); - public static final Block diamond_door = register(new BlockDiamondDoor(Unicopia.MODID, "diamond_door", () -> UItems.diamond_door)); + public static final BlockCloudDoor mist_door = register(new BlockCloudDoor(), "mist_door"); + public static final DutchDoorBlock library_door = register(new DutchDoorBlock(FabricBlockSettings.of(Material.WOOD).sounds(BlockSoundGroup.WOOD).hardness(3).build()), "library_door"); + public static final DutchDoorBlock bakery_door = register(new DutchDoorBlock(FabricBlockSettings.of(Material.WOOD).sounds(BlockSoundGroup.WOOD).hardness(3).build()), "bakery_door"); + public static final DiamondDoorBlock diamond_door = register(new DiamondDoorBlock(), "diamond_door"); - public static final GlowingGemBlock enchanted_torch = register(new GlowingGemBlock(Unicopia.MODID, "enchanted_torch")); + public static final GlowingGemBlock enchanted_torch = register(new GlowingGemBlock(), "enchanted_torch"); - public static final BlockCloudAnvil anvil = register(new BlockCloudAnvil(Unicopia.MODID, "anvil")); + public static final CloudAnvilBlock anvil = register(new CloudAnvilBlock(), "anvil"); - public static final BlockCloudFence cloud_fence = register(new BlockCloudFence(UMaterials.cloud, CloudType.NORMAL, Unicopia.MODID, "cloud_fence")); - public static final BlockCloudBanister cloud_banister = register(new BlockCloudBanister(UMaterials.cloud, Unicopia.MODID, "cloud_banister")); + public static final CloudFenceBlock cloud_fence = register(new CloudFenceBlock(UMaterials.cloud, CloudType.NORMAL), "cloud_fence"); + public static final CloudBanisterBlock cloud_banister = register(new CloudBanisterBlock(UMaterials.cloud), "cloud_banister"); - public static final BlockAlfalfa alfalfa = register(new BlockAlfalfa(Unicopia.MODID, "alfalfa")); + public static final BlockAlfalfa alfalfa = register(new BlockAlfalfa(), "alfalfa"); public static final StickBlock stick = register(new StickBlock(), "stick"); - public static final BlockTomatoPlant tomato_plant = register(new BlockTomatoPlant(Unicopia.MODID, "tomato_plant")); + public static final BlockTomatoPlant tomato_plant = register(new BlockTomatoPlant(), "tomato_plant"); - public static final BlockCloudFarm cloud_farmland = register(new BlockCloudFarm(Unicopia.MODID, "cloud_farmland")); + public static final BlockCloudFarm cloud_farmland = register(new BlockCloudFarm(), "cloud_farmland"); public static final HiveWallBlock hive = register(new HiveWallBlock(), "hive"); public static final ChitinBlock chitin = register(new ChitinBlock(), "chitin_block"); @@ -86,8 +86,10 @@ public class UBlocks { public static final Block sugar_block = register(new SugarBlock(), "sugar_block"); public static final UPot flower_pot = register(new UPot(), "flower_pot"); - public static final USapling apple_tree = register(new USapling(Unicopia.MODID, "apple_sapling") - .setTreeGen((w, s, m) -> new WorldGenTrees(true, 5, Blocks.LOG.getDefaultState(), UBlocks.apple_leaves.getDefaultState(), false)); + public static final SaplingBlock apple_tree = register(new SaplingBlock( + new CustomSaplingGenerator(5, Blocks.OAK_LOG.getDefaultState(), UBlocks.apple_leaves.getDefaultState()), + FabricBlockSettings.of(Material.WOOD).build() + ) {}, "apple_sapling"); public static final Block apple_leaves = register(new FruitLeavesBlock() .growthChance(1200) .tint(0xFFEE81) diff --git a/src/main/java/com/minelittlepony/unicopia/UClient.java b/src/main/java/com/minelittlepony/unicopia/UClient.java deleted file mode 100644 index 094626b8..00000000 --- a/src/main/java/com/minelittlepony/unicopia/UClient.java +++ /dev/null @@ -1,88 +0,0 @@ -package com.minelittlepony.unicopia; - -import java.util.UUID; - -import javax.annotation.Nonnull; -import javax.annotation.Nullable; - -import com.minelittlepony.unicopia.client.UnicopiaClient; -import com.minelittlepony.unicopia.entity.EntityFakeServerPlayer; -import com.minelittlepony.unicopia.entity.capabilities.IPlayer; -import com.mojang.authlib.GameProfile; - -import net.minecraft.entity.Entity; -import net.minecraft.entity.player.PlayerEntity; - -public class UClient { - - private static UClient instance; - - public static boolean isClientSide() { - return false; - } - - public static UClient instance() { - if (instance == null) { - if (isClientSide()) { - instance = new UnicopiaClient(); - } else { - instance = new UClient(); - } - } - - return instance; - } - - public void displayGuiToPlayer(PlayerEntity player, InteractionObject inventory) { - player.displayGui(inventory); - } - - @Nullable - public PlayerEntity getPlayer() { - return null; - } - - @Nullable - public IPlayer getIPlayer() { - return SpeciesList.instance().getPlayer(getPlayer()); - } - - @Nullable - public PlayerEntity getPlayerByUUID(UUID playerId) { - return null; - } - - public boolean isClientPlayer(@Nullable PlayerEntity player) { - return false; - } - - public int getViewMode() { - return 0; - } - - /** - * Side-independent method to create a new player. - * - * Returns an implementation of PlayerEntity appropriate to the side being called on. - */ - @Nonnull - public PlayerEntity createPlayer(Entity observer, GameProfile profile) { - return new EntityFakeServerPlayer((WorldServer)observer.world, profile); - } - - public void postRenderEntity(Entity entity) { - - } - - public boolean renderEntity(Entity entity, float renderPartialTicks) { - return false; - } - - public void tick() {} - - public void preInit() {} - - public void init() {} - - public void postInit() {} -} diff --git a/src/main/java/com/minelittlepony/unicopia/UContainers.java b/src/main/java/com/minelittlepony/unicopia/UContainers.java new file mode 100644 index 00000000..bbbc2d83 --- /dev/null +++ b/src/main/java/com/minelittlepony/unicopia/UContainers.java @@ -0,0 +1,15 @@ +package com.minelittlepony.unicopia; + +import com.minelittlepony.unicopia.inventory.gui.ContainerOfHolding; + +import net.fabricmc.fabric.api.container.ContainerProviderRegistry; +import net.minecraft.util.Identifier; + +public class UContainers { + + public static final Identifier BAG_OF_HOLDING = new Identifier(Unicopia.MODID, "bag_of_holding"); + + static void bootstrap() { + ContainerProviderRegistry.INSTANCE.registerFactory(BAG_OF_HOLDING, ContainerOfHolding::new); + } +} diff --git a/src/main/java/com/minelittlepony/unicopia/UEffects.java b/src/main/java/com/minelittlepony/unicopia/UEffects.java index 7819c4de..173b9241 100644 --- a/src/main/java/com/minelittlepony/unicopia/UEffects.java +++ b/src/main/java/com/minelittlepony/unicopia/UEffects.java @@ -3,24 +3,21 @@ package com.minelittlepony.unicopia; import com.minelittlepony.unicopia.Unicopia; import com.minelittlepony.util.MagicalDamageSource; -import net.minecraft.entity.damage.DamageSource; import net.minecraft.entity.effect.StatusEffect; import net.minecraft.entity.effect.StatusEffectInstance; +import net.minecraft.entity.effect.StatusEffectType; import net.minecraft.entity.effect.StatusEffects; -import net.minecraft.potion.Potion; +import net.minecraft.util.Identifier; public class UEffects { - public static final StatusEffect FOOD_POISONING = new UPotion(Unicopia.MODID, "food_poisoning", true, 3484199) - .setIconIndex(3, 1) + public static final StatusEffect FOOD_POISONING = new CustomStatusEffect(new Identifier(Unicopia.MODID, "food_poisoning"), StatusEffectType.BENEFICIAL, 3484199) .setSilent() - .setEffectiveness(0.25) - .setApplicator((p, e, i) -> { - + .direct((p, e, i) -> { StatusEffectInstance nausea = e.getStatusEffect(StatusEffects.NAUSEA); if (nausea == null) { StatusEffectInstance foodEffect = e.getStatusEffect(p); - nausea = new StatusEffectInstance(StatusEffects.NAUSEA, foodEffect.getDuration(), foodEffect.getAmplifier(), foodEffect.getIsAmbient(), foodEffect.doesShowParticles()); + nausea = new StatusEffectInstance(StatusEffects.NAUSEA, foodEffect.getDuration(), foodEffect.getAmplifier(), foodEffect.isAmbient(), foodEffect.shouldShowParticles()); e.addPotionEffect(nausea); } diff --git a/src/main/java/com/minelittlepony/unicopia/UEntities.java b/src/main/java/com/minelittlepony/unicopia/UEntities.java index d56664b9..06b6fafd 100644 --- a/src/main/java/com/minelittlepony/unicopia/UEntities.java +++ b/src/main/java/com/minelittlepony/unicopia/UEntities.java @@ -2,12 +2,12 @@ package com.minelittlepony.unicopia; import com.minelittlepony.unicopia.entity.ButterflyEntity; import com.minelittlepony.unicopia.entity.CloudEntity; -import com.minelittlepony.unicopia.entity.AdvancedProjectileEntity; +import com.minelittlepony.unicopia.entity.ProjectileEntity; import com.minelittlepony.unicopia.entity.ConstructionCloudEntity; -import com.minelittlepony.unicopia.entity.EntityCuccoon; -import com.minelittlepony.unicopia.entity.EntityRacingCloud; +import com.minelittlepony.unicopia.entity.CuccoonEntity; +import com.minelittlepony.unicopia.entity.RacingCloudEntity; import com.minelittlepony.unicopia.entity.RainbowEntity; -import com.minelittlepony.unicopia.entity.EntitySpear; +import com.minelittlepony.unicopia.entity.SpearEntity; import com.minelittlepony.unicopia.entity.SpellcastEntity; import com.minelittlepony.util.collection.ListHelper; import com.minelittlepony.unicopia.entity.SpellbookEntity; @@ -30,23 +30,23 @@ public class UEntities { public static final EntityType MAGIC_SPELL = register("magic_spell", EntityType.Builder.create(SpellcastEntity::new, EntityCategory.MISC).setDimensions(0.6F, 0.25F)); public static final EntityType CLOUD = register("cloud", EntityType.Builder.create(CloudEntity::new, EntityCategory.CREATURE)); public static final EntityType WILD_CLOUD = register("wild_cloud", EntityType.Builder.create(WildCloudEntity::new, EntityCategory.CREATURE)); - public static final EntityType RACING_CLOUD = register("racing_cloud", EntityType.Builder.create(EntityRacingCloud::new, EntityCategory.CREATURE)); + public static final EntityType RACING_CLOUD = register("racing_cloud", EntityType.Builder.create(RacingCloudEntity::new, EntityCategory.CREATURE)); public static final EntityType CONSTRUCTION_CLOUD = register("construction_cloud", EntityType.Builder.create(ConstructionCloudEntity::new, EntityCategory.CREATURE)); public static final EntityType RAINBOW = register("rainbow", EntityType.Builder.create(RainbowEntity::new, EntityCategory.AMBIENT)); public static final EntityType RAINBOW_SPAWNER = register("rainbow_spawner", EntityType.Builder.create(RainbowEntity.Spawner::new, EntityCategory.MISC)); - public static final EntityType CUCCOON = register("cuccoon", EntityType.Builder.create(EntityCuccoon::new, EntityCategory.MISC).setDimensions(0.6f, 0.6f)); + public static final EntityType CUCCOON = register("cuccoon", EntityType.Builder.create(CuccoonEntity::new, EntityCategory.MISC).setDimensions(1.5F, 1.6F)); public static final EntityType BUTTERFLY = register("butterfly", EntityType.Builder.create(ButterflyEntity::new, EntityCategory.AMBIENT)); - public static final EntityType THROWN_ITEM = register("thrown_item", EntityType.Builder.create(AdvancedProjectileEntity::new, EntityCategory.MISC)); - public static final EntityType THROWN_SPEAR = register("thrown_spear", EntityType.Builder.create(EntitySpear::new, EntityCategory.MISC)); + public static final EntityType THROWN_ITEM = register("thrown_item", EntityType.Builder.create(ProjectileEntity::new, EntityCategory.MISC)); + public static final EntityType THROWN_SPEAR = register("thrown_spear", EntityType.Builder.create(SpearEntity::new, EntityCategory.MISC)); //builder.creature(CloudEntity.class, "cloud").withEgg(0x4169e1, 0x7fff00), //builder.creature(ButterflyEntity.class, "butterfly").withEgg(0x222200, 0xaaeeff), - // builder.projectile(AdvancedProjectileEntity.class, "thrown_item", 100, 10), - // builder.projectile(EntitySpear.class, "spear", 100, 10) + // builder.projectile(ProjectileEntity.class, "thrown_item", 100, 10), + // builder.projectile(SpearEntity.class, "spear", 100, 10) private static EntityType register(String name, EntityType.Builder builder) { return Registry.register(Registry.ENTITY_TYPE, name, builder.build(name)); diff --git a/src/main/java/com/minelittlepony/unicopia/UItems.java b/src/main/java/com/minelittlepony/unicopia/UItems.java index e35ab927..6379dad2 100644 --- a/src/main/java/com/minelittlepony/unicopia/UItems.java +++ b/src/main/java/com/minelittlepony/unicopia/UItems.java @@ -1,34 +1,34 @@ package com.minelittlepony.unicopia; -import com.minelittlepony.unicopia.item.ItemAlicornAmulet; -import com.minelittlepony.unicopia.item.ItemAppleMultiType; -import com.minelittlepony.unicopia.item.ItemCereal; +import com.minelittlepony.unicopia.item.AlicornAmuletItem; +import com.minelittlepony.unicopia.item.SugaryItem; import com.minelittlepony.unicopia.item.AppleItem; import com.minelittlepony.unicopia.item.CloudPlacerItem; import com.minelittlepony.unicopia.item.ExtendedShearsItem; import com.minelittlepony.unicopia.item.CursedMagicGemItem; -import com.minelittlepony.unicopia.item.ItemMagicStaff; +import com.minelittlepony.unicopia.item.EnchantedStaffItem; import com.minelittlepony.unicopia.item.MossItem; -import com.minelittlepony.unicopia.item.ItemOfHolding; +import com.minelittlepony.unicopia.item.BagOfHoldingItem; import com.minelittlepony.unicopia.item.RottenAppleItem; import com.minelittlepony.unicopia.item.RottenTomatoItem; -import com.minelittlepony.unicopia.item.ItemSpear; +import com.minelittlepony.unicopia.item.SpearItem; import com.minelittlepony.unicopia.item.MagicGemItem; import com.minelittlepony.unicopia.item.SpellbookItem; -import com.minelittlepony.unicopia.item.ItemStaff; +import com.minelittlepony.unicopia.item.StaffItem; import com.minelittlepony.unicopia.item.TomatoItem; import com.minelittlepony.unicopia.item.TomatoSeedsItem; -import com.minelittlepony.unicopia.item.ItemZapApple; +import com.minelittlepony.unicopia.item.ZapAppleItem; import com.minelittlepony.unicopia.item.PredicatedBlockItem; import com.minelittlepony.unicopia.item.StickItem; import com.minelittlepony.unicopia.item.URecord; import com.minelittlepony.unicopia.item.consumables.BushToxicityDeterminent; import com.minelittlepony.unicopia.item.consumables.CookedToxicityDeterminent; import com.minelittlepony.unicopia.item.consumables.FlowerToxicityDeterminent; -import com.minelittlepony.unicopia.item.consumables.MultiItemEdible; +import com.minelittlepony.unicopia.item.consumables.DelegatedEdibleItem; import com.minelittlepony.unicopia.item.consumables.Toxicity; -import com.minelittlepony.unicopia.item.consumables.UItemFoodDelegate; +import com.minelittlepony.unicopia.item.consumables.DelegateFoodItem; import com.minelittlepony.unicopia.magic.spells.SpellRegistry; +import com.minelittlepony.unicopia.magic.spells.SpellScorch; import net.minecraft.item.Item; import net.minecraft.item.ItemGroup; @@ -37,6 +37,7 @@ import net.minecraft.block.Blocks; import net.minecraft.client.MinecraftClient; import net.minecraft.client.color.item.ItemColors; import net.minecraft.item.BlockItem; +import net.minecraft.item.FoodComponent; import net.minecraft.item.FoodComponents; import net.minecraft.item.ItemStack; import net.minecraft.item.Items; @@ -50,10 +51,10 @@ import static com.minelittlepony.unicopia.EquinePredicates.*; import javax.annotation.Nullable; -import com.minelittlepony.unicopia.UClient; +import com.minelittlepony.unicopia.ServerInteractionManager; import com.minelittlepony.unicopia.Unicopia; import com.minelittlepony.unicopia.entity.ConstructionCloudEntity; -import com.minelittlepony.unicopia.entity.EntityRacingCloud; +import com.minelittlepony.unicopia.entity.RacingCloudEntity; import com.minelittlepony.unicopia.entity.WildCloudEntity; import com.minelittlepony.unicopia.forgebullshit.BuildInTexturesBakery; import com.minelittlepony.unicopia.forgebullshit.OreReplacer; @@ -69,7 +70,7 @@ public class UItems { public static final AppleItem sweet_apple = register(new AppleItem(FoodComponents.APPLE), "apple_sweet"); public static final AppleItem sour_apple = register(new AppleItem(FoodComponents.APPLE), "apple_sour"); - public static final ItemAppleMultiType zap_apple = new ItemZapApple(Unicopia.MODID, "zap_apple").setSubTypes("zap_apple", "red", "green", "sweet", "sour", "zap"); + public static final ZapAppleItem zap_apple = register(new ZapAppleItem(), "zap_apple"); public static final AppleItem rotten_apple = register(new RottenAppleItem(FoodComponents.APPLE), "rotten_apple"); public static final AppleItem cooked_zap_apple = register(new AppleItem(FoodComponents.APPLE), "cooked_zap_apple"); @@ -77,9 +78,9 @@ public class UItems { public static final Item cloud_matter = register(new Item(new Item.Settings().group(ItemGroup.MATERIALS)), "cloud_matter"); public static final Item dew_drop = register(new Item(new Item.Settings().group(ItemGroup.MATERIALS)), "dew_drop"); - public static final CloudPlacerItem racing_cloud_spawner = register(new CloudPlacerItem(EntityRacingCloud::new), "racing_cloud_spawner"); - public static final CloudPlacerItem construction_cloud_spawner = register(new CloudPlacerItem(ConstructionCloudEntity::new), "construction_cloud_spawner"); - public static final CloudPlacerItem wild_cloud_spawner = register(new CloudPlacerItem(WildCloudEntity::new), "wild_cloud_spawner"); + public static final CloudPlacerItem racing_cloud_spawner = register(new CloudPlacerItem(UEntities.RACING_CLOUD), "racing_cloud_spawner"); + public static final CloudPlacerItem construction_cloud_spawner = register(new CloudPlacerItem(UEntities.CONSTRUCTION_CLOUD), "construction_cloud_spawner"); + public static final CloudPlacerItem wild_cloud_spawner = register(new CloudPlacerItem(UEntities.WILD_CLOUD), "wild_cloud_spawner"); public static final Item cloud_block = register(new PredicatedBlockItem(UBlocks.normal_cloud, new Item.Settings().group(ItemGroup.MATERIALS), INTERACT_WITH_CLOUDS), "cloud_block"); public static final Item enchanted_cloud = register(new PredicatedBlockItem(UBlocks.enchanted_cloud, new Item.Settings().group(ItemGroup.MATERIALS), INTERACT_WITH_CLOUDS), "enchanted_cloud_block"); @@ -118,36 +119,53 @@ public class UItems { public static final MagicGemItem spell = register(new MagicGemItem(), "gem"); public static final MagicGemItem curse = register(new CursedMagicGemItem(), "corrupted_gem"); - public static final ItemOfHolding bag_of_holding = new ItemOfHolding(Unicopia.MODID, "bag_of_holding"); - public static final ItemAlicornAmulet alicorn_amulet = new ItemAlicornAmulet(Unicopia.MODID, "alicorn_amulet"); + public static final BagOfHoldingItem bag_of_holding = register(new BagOfHoldingItem(), "bag_of_holding"); + public static final AlicornAmuletItem alicorn_amulet = register(new AlicornAmuletItem(), "alicorn_amulet"); public static final SpellbookItem spellbook = register(new SpellbookItem(), "spellbook"); - public static final Item staff_meadow_brook = new ItemStaff(Unicopia.MODID, "staff_meadow_brook").setMaxDamage(2); - public static final Item staff_remembrance = new ItemMagicStaff(Unicopia.MODID, "staff_remembrance", new SpellScorch()); + public static final Item staff_meadow_brook = register(new StaffItem(new Item.Settings().maxCount(1).maxDamage(2)), "staff_meadow_brook"); + public static final Item staff_remembrance = register(new EnchantedStaffItem(new Item.Settings(), new SpellScorch()), "staff_remembrance"); - public static final Item spear = new ItemSpear(Unicopia.MODID, "spear"); + public static final Item spear = register(new SpearItem(new Item.Settings().maxCount(1).maxDamage(500)), "spear"); - public static final MossItem moss = new MossItem(Unicopia.MODID, "moss"); + public static final MossItem moss = register(new MossItem(new Item.Settings()), "moss"); public static final Item alfalfa_seeds = new ItemSeedFood(1, 4, UBlocks.alfalfa, Blocks.FARMLAND) .setTranslationKey("alfalfa_seeds") .setRegistryName(Unicopia.MODID, "alfalfa_seeds") .setCreativeTab(CreativeTabs.MATERIALS); - public static final Item enchanted_torch = register(new BlockItem(UBlocks.enchanted_torch), "enchanted_torch"); + public static final Item enchanted_torch = register(new BlockItem(UBlocks.enchanted_torch, new Item.Settings().group(ItemGroup.DECORATIONS)), "enchanted_torch"); - public static final Item alfalfa_leaves = new FoodItem(1, 3, false) - .setTranslationKey("alfalfa_leaves") - .setRegistryName(Unicopia.MODID, "alfalfa_leaves"); + public static final Item alfalfa_leaves = register(new Item(new Item.Settings() + .group(ItemGroup.FOOD) + .food(new FoodComponent.Builder() + .hunger(1) + .saturationModifier(3) + .build())), "alfalfa_leaves"); - public static final Item cereal = new ItemCereal(Unicopia.MODID, "cereal", 9, 0.8F).setSugarAmount(1); - public static final Item sugar_cereal = new ItemCereal(Unicopia.MODID, "sugar_cereal", 20, -2).setSugarAmount(110).setAlwaysEdible(); + public static final Item cereal = register(new SugaryItem(new Item.Settings() + .group(ItemGroup.FOOD) + .food(new FoodComponent.Builder() + .hunger(9) + .saturationModifier(0.8F) + .build()) + .maxCount(1) + .recipeRemainder(Items.BOWL), 1), "cereal"); + public static final Item sugar_cereal = register(new SugaryItem(new Item.Settings() + .group(ItemGroup.FOOD) + .food(new FoodComponent.Builder() + .hunger(20) + .saturationModifier(-2) + .build()) + .maxCount(1) + .recipeRemainder(Items.BOWL), 110), "sugar_cereal"); - public static final TomatoItem tomato = new TomatoItem(Unicopia.MODID, "tomato", 4, 34); - public static final RottenTomatoItem rotten_tomato = new RottenTomatoItem(Unicopia.MODID, "rotten_tomato", 4, 34); + public static final TomatoItem tomato = register(new TomatoItem(4, 34), "tomato"); + public static final RottenTomatoItem rotten_tomato = register(new RottenTomatoItem(4, 34), "rotten_tomato"); - public static final TomatoItem cloudsdale_tomato = new TomatoItem(Unicopia.MODID, "cloudsdale_tomato", 16, 4); - public static final RottenTomatoItem rotten_cloudsdale_tomato = new RottenTomatoItem(Unicopia.MODID, "rotten_cloudsdale_tomato", 4, 34); + public static final TomatoItem cloudsdale_tomato = register(new TomatoItem(16, 4), "cloudsdale_tomato"); + public static final RottenTomatoItem rotten_cloudsdale_tomato = register(new RottenTomatoItem(5, 34), "rotten_cloudsdale_tomato"); public static final TomatoSeedsItem tomato_seeds = new TomatoSeedsItem(Unicopia.MODID, "tomato_seeds"); @@ -155,19 +173,19 @@ public class UItems { public static final Item apple_leaves = new BlockItem(UBlocks.apple_leaves); - public static final Item double_plant = new UItemFoodDelegate(Blocks.DOUBLE_PLANT, stack -> + public static final Item double_plant = new DelegateFoodItem(Blocks.TALL_GRASS, stack -> BlockDoublePlant.EnumPlantType.byMetadata(stack.getMetadata()).getTranslationKey() - ).setFoodDelegate(new MultiItemEdible(new BushToxicityDeterminent())) + ).setFoodDelegate(new DelegatedEdibleItem(new BushToxicityDeterminent())) .setTranslationKey("doublePlant"); - public static final Item tall_grass = new UItemFoodDelegate(Blocks.TALLGRASS, stack -> { + public static final Item tall_grass = new DelegateFoodItem(Blocks.GRASS, stack -> { switch (stack.getMetadata()) { case 0: return "shrub"; case 1: return "grass"; case 2: return "fern"; default: return ""; } - }).setFoodDelegate(new MultiItemEdible(stack -> { + }).setFoodDelegate(new DelegatedEdibleItem(stack -> { switch (stack.getMetadata()) { default: case 0: return Toxicity.SAFE; @@ -176,63 +194,39 @@ public class UItems { } })); - public static final Item yellow_flower = new UItemFoodDelegate(Blocks.YELLOW_FLOWER, stack -> + public static final Item yellow_flower = new DelegateFoodItem(Blocks.YELLOW_FLOWER, stack -> BlockFlower.EnumFlowerType.getType(BlockFlower.EnumFlowerColor.YELLOW, stack.getMetadata()).getTranslationKey() - ).setFoodDelegate(new MultiItemEdible(new FlowerToxicityDeterminent(BlockFlower.EnumFlowerColor.YELLOW))) + ).setFoodDelegate(new DelegatedEdibleItem(new FlowerToxicityDeterminent(BlockFlower.EnumFlowerColor.YELLOW))) .setTranslationKey("flower"); - public static final Item red_flower = new UItemFoodDelegate(Blocks.RED_FLOWER, stack -> + public static final Item red_flower = new DelegateFoodItem(Blocks.RED_FLOWER, stack -> BlockFlower.EnumFlowerType.getType(BlockFlower.EnumFlowerColor.RED, stack.getMetadata()).getTranslationKey() - ).setFoodDelegate(new MultiItemEdible(new FlowerToxicityDeterminent(BlockFlower.EnumFlowerColor.RED))) + ).setFoodDelegate(new DelegatedEdibleItem(new FlowerToxicityDeterminent(BlockFlower.EnumFlowerColor.RED))) .setTranslationKey("rose"); - public static final Item daffodil_daisy_sandwich = new MultiItemEdible(Unicopia.MODID, "daffodil_daisy_sandwich", 3, 2, CookedToxicityDeterminent.instance) + public static final Item daffodil_daisy_sandwich = new DelegatedEdibleItem(Unicopia.MODID, "daffodil_daisy_sandwich", 3, 2, CookedToxicityDeterminent.instance) .setHasSubtypes(true); - public static final Item hay_burger = new MultiItemEdible(Unicopia.MODID, "hay_burger", 3, 4, CookedToxicityDeterminent.instance) + public static final Item hay_burger = new DelegatedEdibleItem(Unicopia.MODID, "hay_burger", 3, 4, CookedToxicityDeterminent.instance) .setHasSubtypes(true); - public static final Item hay_fries = new MultiItemEdible(Unicopia.MODID, "hay_fries", 1, 5, stack -> Toxicity.SAFE); - public static final Item salad = new MultiItemEdible(Unicopia.MODID, "salad", 4, 2, CookedToxicityDeterminent.instance) + public static final Item hay_fries = new DelegatedEdibleItem(Unicopia.MODID, "hay_fries", 1, 5, stack -> Toxicity.SAFE); + public static final Item salad = new DelegatedEdibleItem(Unicopia.MODID, "salad", 4, 2, CookedToxicityDeterminent.instance) .setHasSubtypes(true) .setContainerItem(Items.BOWL); - public static final Item wheat_worms = new MultiItemEdible(Unicopia.MODID, "wheat_worms", 1, 0, stack -> Toxicity.SEVERE); + public static final Item wheat_worms = new DelegatedEdibleItem(Unicopia.MODID, "wheat_worms", 1, 0, stack -> Toxicity.SEVERE); public static final Item mug = register(new Item(new Item.Settings().group(ItemGroup.MATERIALS)), "mug"); - public static final Item apple_cider = new MultiItemEdible(Unicopia.MODID, "apple_cider", 4, 2, stack -> Toxicity.MILD) + public static final Item apple_cider = new DelegatedEdibleItem(Unicopia.MODID, "apple_cider", 4, 2, stack -> Toxicity.MILD) .setUseAction(UseAction.DRINK) .setContainerItem(mug) .setFull3D(); - public static final Item juice = new MultiItemEdible(Unicopia.MODID, "juice", 2, 2, stack -> Toxicity.SAFE) + public static final Item juice = new DelegatedEdibleItem(Unicopia.MODID, "juice", 2, 2, stack -> Toxicity.SAFE) .setUseAction(UseAction.DRINK) .setContainerItem(Items.GLASS_BOTTLE); - public static final Item burned_juice = new MultiItemEdible(Unicopia.MODID, "burned_juice", 3, 1, stack -> Toxicity.FAIR) + public static final Item burned_juice = new DelegatedEdibleItem(Unicopia.MODID, "burned_juice", 3, 1, stack -> Toxicity.FAIR) .setUseAction(UseAction.DRINK) .setContainerItem(Items.GLASS_BOTTLE); - - static void init(IForgeRegistry registry) { - RegistryLockSpinner.open(Item.REGISTRY, Items.class, r -> r - .replace(Items.APPLE, red_apple) - .replace(Item.getItemFromBlock(Blocks.TALLGRASS), tall_grass) - .replace(Item.getItemFromBlock(Blocks.DOUBLE_PLANT), double_plant) - .replace(Item.getItemFromBlock(Blocks.YELLOW_FLOWER), yellow_flower) - .replace(Item.getItemFromBlock(Blocks.RED_FLOWER), red_flower)); - - if (UClient.isClientSide()) { - BuildInTexturesBakery.getBuiltInTextures().add(new Identifier(Unicopia.MODID, "items/empty_slot_gem")); - } - - FurnaceRecipes.instance().addSmeltingRecipe(new ItemStack(zap_apple), new ItemStack(cooked_zap_apple), 0.1F); - FurnaceRecipes.instance().addSmeltingRecipe(new ItemStack(juice), new ItemStack(burned_juice), 0); - FurnaceRecipes.instance().addSmeltingRecipe(new ItemStack(cuccoon), new ItemStack(chitin_shell), 0.3F); - } - - static void fixRecipes() { - new OreReplacer() - .registerAll(stack -> stack.getItem().getRegistryName().equals(red_apple.getRegistryName())) - .done(); - } - private static T register(T item, String namespace, String name) { return Registry.ITEM.add(new Identifier(namespace, name), item); } @@ -240,15 +234,33 @@ public class UItems { return register(item, name); } - static void registerColors(ItemColors registry) { - registry.register((stack, tint) -> { - if (MAGI.test(MinecraftClient.getInstance().player)) { - return SpellRegistry.instance().getSpellTintFromStack(stack); - } + static void bootstrap() { + RegistryLockSpinner.open(Item.REGISTRY, Items.class, r -> r + .replace(Items.APPLE, red_apple) + .replace(Item.getItemFromBlock(Blocks.TALLGRASS), tall_grass) + .replace(Item.getItemFromBlock(Blocks.DOUBLE_PLANT), double_plant) + .replace(Item.getItemFromBlock(Blocks.YELLOW_FLOWER), yellow_flower) + .replace(Item.getItemFromBlock(Blocks.RED_FLOWER), red_flower)); - return 0xffffff; - }, spell, curse); + if (ServerInteractionManager.isClientSide()) { + BuildInTexturesBakery.getBuiltInTextures().add(new Identifier(Unicopia.MODID, "items/empty_slot_gem")); + + ItemColors registry; + registry.register((stack, tint) -> { + if (MAGI.test(MinecraftClient.getInstance().player)) { + return SpellRegistry.instance().getSpellTintFromStack(stack); + } + + return 0xffffff; + }, spell, curse); + } + + FurnaceRecipes.instance().addSmeltingRecipe(new ItemStack(zap_apple), new ItemStack(cooked_zap_apple), 0.1F); + FurnaceRecipes.instance().addSmeltingRecipe(new ItemStack(juice), new ItemStack(burned_juice), 0); + FurnaceRecipes.instance().addSmeltingRecipe(new ItemStack(cuccoon), new ItemStack(chitin_shell), 0.3F); + + new OreReplacer() + .registerAll(stack -> stack.getItem().getRegistryName().equals(red_apple.getRegistryName())) + .done(); } - - static void bootstrap() {} } diff --git a/src/main/java/com/minelittlepony/unicopia/UPotion.java b/src/main/java/com/minelittlepony/unicopia/UPotion.java deleted file mode 100644 index e7c00cdd..00000000 --- a/src/main/java/com/minelittlepony/unicopia/UPotion.java +++ /dev/null @@ -1,100 +0,0 @@ -package com.minelittlepony.unicopia; - -import javax.annotation.Nonnull; - -import net.minecraft.entity.LivingEntity; -import net.minecraft.entity.effect.StatusEffect; -import net.minecraft.potion.Potion; - -public class UPotion extends StatusEffect { - - private boolean isSilent; - private int tickDelay = 40; - - @Nonnull - private IEffectApplicator applicator = IEffectApplicator.NONE; - - public UPotion(String domain, String name, boolean isNegative, int tint) { - super(isNegative, tint); - - setRegistryName(domain, name); - setPotionName("effect." + name); - } - - public UPotion setSilent() { - isSilent = true; - - return this; - } - - public UPotion setApplicator(@Nonnull IEffectApplicator applicator) { - this.applicator = applicator; - - return this; - } - - public UPotion setTickDelay(int delay) { - tickDelay = delay; - - return this; - } - - @Override - public UPotion setIconIndex(int u, int v) { - super.setIconIndex(u, v); - - return this; - } - - @Override - public UPotion setEffectiveness(double effectiveness) { - super.setEffectiveness(effectiveness); - - return this; - } - - @Override - public boolean shouldRender(StatusEffectInstance effect) { - return !isSilent; - } - - @Override - public boolean shouldRenderInvText(StatusEffectInstance effect) { - return !isSilent; - } - - @Override - public boolean shouldRenderHUD(StatusEffectInstance effect) { - return !isSilent; - } - - @Override - public void performEffect(LivingEntity entity, int amplifier) { - applicator.performEffect(this, entity, amplifier); - } - - @Override - public boolean isInstant() { - return tickDelay > 0; - } - - @Override - public boolean isReady(int duration, int amplifier) { - if (!isInstant()) { - int i = tickDelay >> amplifier; - - if (i > 0) { - return duration % i == 0; - } - } - - return duration > 0; - } - - @FunctionalInterface - public interface IEffectApplicator { - IEffectApplicator NONE = (p, e, i) -> {}; - - void performEffect(Potion effect, LivingEntity target, int amplifier); - } -} diff --git a/src/main/java/com/minelittlepony/unicopia/Unicopia.java b/src/main/java/com/minelittlepony/unicopia/Unicopia.java index 4af24aac..ab5a0527 100644 --- a/src/main/java/com/minelittlepony/unicopia/Unicopia.java +++ b/src/main/java/com/minelittlepony/unicopia/Unicopia.java @@ -23,7 +23,6 @@ import com.minelittlepony.unicopia.inventory.gui.GuiSpellBook; import com.minelittlepony.unicopia.network.MsgPlayerAbility; import com.minelittlepony.unicopia.network.MsgPlayerCapabilities; import com.minelittlepony.unicopia.network.MsgRequestCapabilities; -import com.minelittlepony.unicopia.util.crafting.CraftingManager; import com.minelittlepony.unicopia.world.UWorld; public class Unicopia implements ModInitializer { @@ -33,25 +32,10 @@ public class Unicopia implements ModInitializer { public static final Logger LOGGER = LogManager.getLogger(); + static InteractionManager interactionManager; + private static IChannel channel; - private static CraftingManager craftingManager = new CraftingManager(MODID, "enchanting") { - @Override - protected void registerRecipeTypes(Map> types) { - super.registerRecipeTypes(types); - - types.put("unicopia:crafting_spell", SpellRecipe::deserialize); - types.put("unicopia:crafting_special", SpecialRecipe::deserialize); - - AffineIngredients.instance().load(); - } - }; - - @Deprecated - public static CraftingManager getCraftingManager() { - return craftingManager; - } - public static IChannel getConnection() { return channel; } @@ -76,13 +60,13 @@ public class Unicopia implements ModInitializer { UBlocks.bootstrap(); UItems.bootstrap(); Commands.bootstrap(); - + UContainers.bootstrap(); UWorld.instance().init(); - UClient.instance().preInit(); - UClient.instance().init(); - UClient.instance().postInit(); + InteractionManager.instance().preInit(); + InteractionManager.instance().init(); + InteractionManager.instance().postInit(); UItems.fixRecipes(); } diff --git a/src/main/java/com/minelittlepony/unicopia/ability/PowerEngulf.java b/src/main/java/com/minelittlepony/unicopia/ability/PowerEngulf.java index 61065023..c2f5d964 100644 --- a/src/main/java/com/minelittlepony/unicopia/ability/PowerEngulf.java +++ b/src/main/java/com/minelittlepony/unicopia/ability/PowerEngulf.java @@ -5,7 +5,7 @@ import javax.annotation.Nullable; import org.lwjgl.glfw.GLFW; import com.minelittlepony.unicopia.Race; import com.minelittlepony.unicopia.entity.capabilities.IPlayer; -import com.minelittlepony.unicopia.magic.spells.SpellChangelingTrap; +import com.minelittlepony.unicopia.magic.spells.ChangelingTrapSpell; public class PowerEngulf implements IPower { @@ -47,7 +47,7 @@ public class PowerEngulf implements IPower { @Override public void apply(IPlayer player, Hit data) { - new SpellChangelingTrap().toss(player); + new ChangelingTrapSpell().toss(player); } @Override diff --git a/src/main/java/com/minelittlepony/unicopia/block/AbstractDoorBlock.java b/src/main/java/com/minelittlepony/unicopia/block/AbstractDoorBlock.java new file mode 100644 index 00000000..c0299de2 --- /dev/null +++ b/src/main/java/com/minelittlepony/unicopia/block/AbstractDoorBlock.java @@ -0,0 +1,128 @@ +package com.minelittlepony.unicopia.block; + +import javax.annotation.Nullable; + +import com.minelittlepony.util.WorldEvent; + +import net.minecraft.block.Block; +import net.minecraft.block.BlockState; +import net.minecraft.block.DoorBlock; +import net.minecraft.block.Material; +import net.minecraft.block.enums.DoubleBlockHalf; +import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.util.Hand; +import net.minecraft.util.hit.BlockHitResult; +import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.Direction; +import net.minecraft.world.World; + +public abstract class AbstractDoorBlock extends DoorBlock { + + protected AbstractDoorBlock(Settings settings) { + super(settings); + } + + protected WorldEvent getCloseSound() { + return isLockable() ? WorldEvent.IRON_DOOR_SLAM : WorldEvent.WOODEN_DOOR_SLAM; + } + + protected WorldEvent getOpenSound() { + return isLockable() ? WorldEvent.IRON_DOOR_OPEN : WorldEvent.WOODEN_DOOR_OPEN; + } + + @Override + public boolean activate(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit) { + return toggleDoor(world, pos, false, true, player); + } + + @Override + public void setOpen(World world, BlockPos pos, boolean open) { + toggleDoor(world, pos, open, false, null); + } + + protected boolean isLockable() { + return material == Material.METAL; + } + + protected boolean canBePowered() { + return true; + } + + protected boolean canOpen(@Nullable PlayerEntity player) { + return player == null || material != Material.METAL; + } + + protected boolean toggleDoor(World world, BlockPos pos, boolean open, boolean force, @Nullable PlayerEntity player) { + if (!canOpen(player)) { + return false; + } + + BlockState state = world.getBlockState(pos); + + if (state.getBlock() != this) { + return false; + } + + BlockPos lower = getPrimaryDoorPos(state, pos); + + BlockState mainDoor = pos == lower ? state : world.getBlockState(lower); + + if (mainDoor.getBlock() != this) { + return false; + } + + if (!force && mainDoor.get(OPEN) == open) { + return false; + } + + state = mainDoor.cycle(OPEN); + + world.setBlockState(lower, state, 10); + + WorldEvent sound = state.get(OPEN) ? getOpenSound() : getCloseSound(); + + world.playLevelEvent(player, sound.getId(), pos, 0); + + return true; + } + + protected BlockPos getPrimaryDoorPos(BlockState state, BlockPos pos) { + return state.get(HALF) == DoubleBlockHalf.LOWER ? pos : pos.down(); + } + + @Override + public void neighborUpdate(BlockState state, World world, BlockPos pos, Block sender, BlockPos blockPos_2, boolean boolean_1) { + if (!canBePowered()) { + return; + } + + BlockPos otherHalf = pos.offset(state.get(HALF) == DoubleBlockHalf.LOWER ? Direction.UP : Direction.DOWN); + + boolean powered = world.isReceivingRedstonePower(pos) || world.isReceivingRedstonePower(otherHalf); + + if (sender != this && powered != state.get(POWERED)) { + world.setBlockState(pos, state.with(POWERED, powered), 2); + + if (onPowerStateChanged(world, state.with(POWERED, powered), pos, powered)) { + playToggleSound(world, pos, powered); + } + } + } + + protected void playToggleSound(World world, BlockPos pos, boolean powered) { + world.playLevelEvent(null, (powered ? getOpenSound() : getCloseSound()).getId(), pos, 0); + } + + /** + * Called by the lower block when the powered state changes. + */ + protected boolean onPowerStateChanged(World world, BlockState state, BlockPos pos, boolean powered) { + if (powered != state.get(OPEN)) { + world.setBlockState(pos, state.with(OPEN, powered), 2); + + return true; + } + + return false; + } +} diff --git a/src/main/java/com/minelittlepony/unicopia/block/BlockCloudAnvil.java b/src/main/java/com/minelittlepony/unicopia/block/BlockCloudAnvil.java deleted file mode 100644 index d1300f5e..00000000 --- a/src/main/java/com/minelittlepony/unicopia/block/BlockCloudAnvil.java +++ /dev/null @@ -1,151 +0,0 @@ -package com.minelittlepony.unicopia.block; - -import java.util.List; -import java.util.Random; - -import javax.annotation.Nullable; - -import com.minelittlepony.unicopia.CloudType; -import com.minelittlepony.util.WorldEvent; - -import net.minecraft.block.AnvilBlock; -import net.minecraft.entity.Entity; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.item.ItemStack; -import net.minecraft.util.math.Box; -import net.minecraft.util.math.BlockPos; -import net.minecraft.util.math.Vec3d; -import net.minecraft.world.BlockView; -import net.minecraft.world.World; - -public class BlockCloudAnvil extends AnvilBlock implements ICloudBlock { - public BlockCloudAnvil(String domain, String name) { - super(); - - setSoundType(SoundType.CLOTH); - setHardness(0.025F); - setResistance(2000); - setRegistryName(domain, name); - setTranslationKey(name); - } - - @Override - public BlockRenderLayer getRenderLayer() { - return BlockRenderLayer.TRANSLUCENT; - } - - @Override - public String getHarvestTool(BlockState state) { - return "shovel"; - } - - @Override - public int getHarvestLevel(BlockState state) { - return 0; - } - - @Override - public void onFallenUpon(World world, BlockPos pos, Entity entityIn, float fallDistance) { - if (!applyLanding(entityIn, fallDistance)) { - super.onFallenUpon(world, pos, entityIn, fallDistance); - } - } - - @Override - public void onEndFalling(World world, BlockPos pos, BlockState fallingState, BlockState hitState) { - WorldEvent.ENTITY_TAKEOFF.play(world, pos); - } - - @Override - public void onBroken(World world, BlockPos pos) { - WorldEvent.ENTITY_TAKEOFF.play(world, pos); - } - - @Override - public boolean onBlockActivated(World worldIn, BlockPos pos, BlockState state, PlayerEntity playerIn, EnumHand hand, Direction facing, float hitX, float hitY, float hitZ) { - return false; - } - - @Override - protected void onStartFalling(EntityFallingBlock fallingEntity) { - fallingEntity.setHurtEntities(true); - } - - @Override - public void onLanded(World worldIn, Entity entity) { - if (!applyRebound(entity)) { - super.onLanded(worldIn, entity); - } - } - - @Override - public boolean isAir(BlockState state, BlockView world, BlockPos pos) { - return allowsFallingBlockToPass(state, world, pos); - } - - @Override - public void updateTick(World world, BlockPos pos, BlockState state, Random rand) { - BlockState below = world.getBlockState(pos.down()); - - if (below.getBlock() instanceof ICloudBlock) { - if (((ICloudBlock)below.getBlock()).isDense(below)) { - return; - } - } - - super.updateTick(world, pos, state, rand); - } - - @Override - public void onEntityCollision(World w, BlockPos pos, BlockState state, Entity entity) { - if (!applyBouncyness(state, entity)) { - super.onEntityCollision(w, pos, state, entity); - } - } - - @Override - public boolean canHarvestBlock(BlockView world, BlockPos pos, PlayerEntity player) { - return getCanInteract(world.getBlockState(pos), player); - } - - @Override - public void getSubBlocks(CreativeTabs itemIn, NonNullList items) { - items.add(new ItemStack(this)); - } - - @Override - public boolean canEntityDestroy(BlockState state, BlockView world, BlockPos pos, Entity entity) { - return getCanInteract(state, entity) && super.canEntityDestroy(state, world, pos, entity); - } - - @Deprecated - public void addCollisionBoxToList(BlockState state, World worldIn, BlockPos pos, Box entityBox, List collidingBoxes, @Nullable Entity entity, boolean p_185477_7_) { - if (getCanInteract(state, entity)) { - super.addCollisionBoxToList(state, worldIn, pos, entityBox, collidingBoxes, entity, p_185477_7_); - } - } - - @Deprecated - @Override - public RayTraceResult collisionRayTrace(BlockState blockState, World worldIn, BlockPos pos, Vec3d start, Vec3d end) { - if (!handleRayTraceSpecialCases(worldIn, pos, blockState)) { - return super.collisionRayTrace(blockState, worldIn, pos, start, end); - } - return null; - } - - @Deprecated - @Override - public float getPlayerRelativeBlockHardness(BlockState state, PlayerEntity player, World worldIn, BlockPos pos) { - if (!CloudType.NORMAL.canInteract(player)) { - return -1; - } - return super.getPlayerRelativeBlockHardness(state, player, worldIn, pos); - } - - - @Override - public CloudType getCloudMaterialType(BlockState blockState) { - return CloudType.NORMAL; - } -} diff --git a/src/main/java/com/minelittlepony/unicopia/block/BlockCloudBanister.java b/src/main/java/com/minelittlepony/unicopia/block/BlockCloudBanister.java deleted file mode 100644 index 4be19e45..00000000 --- a/src/main/java/com/minelittlepony/unicopia/block/BlockCloudBanister.java +++ /dev/null @@ -1,137 +0,0 @@ -package com.minelittlepony.unicopia.block; - -import java.util.List; - -import javax.annotation.Nullable; - -import com.minelittlepony.unicopia.CloudType; - -import net.minecraft.block.BlockRenderLayer; -import net.minecraft.block.Material; -import net.minecraft.entity.Entity; -import net.minecraft.util.math.Box; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.BlockView; -import net.minecraft.world.World; - -public class BlockCloudBanister extends BlockCloudFence { - - public static final double l = 11/16D; - public static final double d = 5/16D; - public static final double h = 2/16D; - - public static final Box SOUTH_AABB = new Box(d, 0, l, l, h, 1); - public static final Box WEST_AABB = new Box(0, 0, d, d, h, l); - public static final Box NORTH_AABB = new Box(d, 0, 0, l, h, d); - public static final Box EAST_AABB = new Box(l, 0, d, 1, h, l); - - public static final Box[] BOUNDING_BOXES = new Box[] { - new Box(d, 0, d, l, h, l), - new Box(d, 0, d, l, h, 1), - new Box(0, 0, d, l, h, l), - new Box(0, 0, d, l, h, 1), - new Box(d, 0, 0, l, h, l), - new Box(d, 0, 0, l, h, 1), - new Box(0, 0, 0, l, h, l), - new Box(0, 0, 0, l, h, 1), - new Box(d, 0, d, 1, h, l), - new Box(d, 0, d, 1, h, 1), - new Box(0, 0, d, 1, h, l), - new Box(0, 0, d, 1, h, 1), - new Box(d, 0, 0, 1, h, l), - new Box(d, 0, 0, 1, h, 1), - new Box(0, 0, 0, 1, h, l), - new Box(0, 0, 0, 1, h, 1) - }; - - public BlockCloudBanister(Material material, String domain, String name) { - super(material, CloudType.ENCHANTED, domain, name); - } - - @Override - public BlockRenderLayer getRenderLayer() { - return BlockRenderLayer.SOLID; - } - - @Override - public boolean canConnectTo(BlockView world, BlockPos pos, Direction facing) { - BlockState myState = world.getBlockState(pos); - - return myState.getBlock() instanceof BlockCloudBanister - && super.canConnectTo(world, pos, facing); - } - - @Override - public boolean canBeConnectedTo(BlockView world, BlockPos pos, Direction facing) { - BlockState state = world.getBlockState(pos.offset(facing)); - - return state.getBlock() instanceof BlockCloudBanister - && state.getMaterial() == world.getBlockState(pos).getMaterial(); - } - - @Deprecated - @Override - public void addCollisionBoxToList(BlockState state, World world, BlockPos pos, Box entityBox, List collidingBoxes, @Nullable Entity entity, boolean isActualState) { - if (!getCanInteract(state, entity)) { - return; - } - - if (!isActualState) { - state = state.getActualState(world, pos); - } - - if (state.getValue(NORTH)) { - addCollisionBoxToList(pos, entityBox, collidingBoxes, NORTH_AABB); - } - - if (state.getValue(EAST)) { - addCollisionBoxToList(pos, entityBox, collidingBoxes, EAST_AABB); - } - - if (state.getValue(SOUTH)) { - addCollisionBoxToList(pos, entityBox, collidingBoxes, SOUTH_AABB); - } - - if (state.getValue(WEST)) { - addCollisionBoxToList(pos, entityBox, collidingBoxes, WEST_AABB); - } - } - - @Override - public boolean isTopSolid(BlockState state) { - return false; - } - - @Override - public boolean canPlaceTorchOnTop(BlockState state, BlockView world, BlockPos pos) { - return false; - } - - @Override - public Box getBoundingBox(BlockState state, BlockView source, BlockPos pos) { - state = state.getActualState(source, pos); - return BOUNDING_BOXES[getBoundingBoxIdx(state)]; - } - - public static int getBoundingBoxIdx(BlockState state) { - int i = 0; - - if (state.getValue(NORTH)) { - i |= 1 << Direction.NORTH.getHorizontalIndex(); - } - - if (state.getValue(EAST)) { - i |= 1 << Direction.EAST.getHorizontalIndex(); - } - - if (state.getValue(SOUTH)) { - i |= 1 << Direction.SOUTH.getHorizontalIndex(); - } - - if (state.getValue(WEST)) { - i |= 1 << Direction.WEST.getHorizontalIndex(); - } - - return i; - } -} diff --git a/src/main/java/com/minelittlepony/unicopia/block/BlockCloudDoor.java b/src/main/java/com/minelittlepony/unicopia/block/BlockCloudDoor.java index 4390997c..b7343e15 100644 --- a/src/main/java/com/minelittlepony/unicopia/block/BlockCloudDoor.java +++ b/src/main/java/com/minelittlepony/unicopia/block/BlockCloudDoor.java @@ -1,61 +1,41 @@ package com.minelittlepony.unicopia.block; -import java.util.function.Supplier; - import com.minelittlepony.unicopia.CloudType; +import com.minelittlepony.unicopia.UMaterials; -import net.minecraft.block.SoundType; -import net.minecraft.block.material.MapColor; -import net.minecraft.block.material.Material; -import net.minecraft.block.state.BlockState; +import net.fabricmc.fabric.api.block.FabricBlockSettings; +import net.minecraft.block.BlockRenderLayer; +import net.minecraft.block.BlockState; import net.minecraft.entity.Entity; import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.item.Item; -import net.minecraft.util.BlockRenderLayer; -import net.minecraft.util.Direction; -import net.minecraft.util.EnumHand; +import net.minecraft.sound.BlockSoundGroup; +import net.minecraft.util.Hand; +import net.minecraft.util.hit.BlockHitResult; import net.minecraft.util.math.BlockPos; import net.minecraft.world.BlockView; import net.minecraft.world.World; -public class BlockCloudDoor extends UDoor implements ICloudBlock { +public class BlockCloudDoor extends AbstractDoorBlock implements ICloudBlock { - public BlockCloudDoor(Material material, String domain, String name, Supplier theItem) { - super(material, domain, name, theItem); - - setSoundType(SoundType.CLOTH); - setHardness(3); - setResistance(200); + @SuppressWarnings("deprecation") + public BlockCloudDoor() { + super(FabricBlockSettings.of(UMaterials.cloud) + .sounds(BlockSoundGroup.WOOL) + .hardness(3) + .resistance(200) + .breakByTool(net.fabricmc.fabric.api.tools.FabricToolTags.SHOVELS, 0) + .build()); } @Override - public MapColor getMapColor(BlockState state, BlockView worldIn, BlockPos pos) { - return blockMapColor; - } - - @Override - public boolean onBlockActivated(World worldIn, BlockPos pos, BlockState state, PlayerEntity player, EnumHand hand, Direction facing, float hitX, float hitY, float hitZ) { - if (!getCanInteract(state, player)) { - return false; - } - - return super.onBlockActivated(worldIn, pos, state, player, hand, facing, hitX, hitY, hitZ); - } - - @Override - public String getHarvestTool(BlockState state) { - return "shovel"; - } - - @Override - public int getHarvestLevel(BlockState state) { - return 0; + public boolean activate(BlockState state, World worldIn, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit) { + return getCanInteract(state, player) && super.activate(state, worldIn, pos, player, hand, hit); } @Deprecated @Override - public float getBlockHardness(BlockState blockState, World world, BlockPos pos) { - float hardness = super.getBlockHardness(blockState, world, pos); + public float getHardness(BlockState blockState, BlockView world, BlockPos pos) { + float hardness = super.getHardness(blockState, world, pos); return Math.max(hardness, Math.min(60, hardness + (pos.getY() - 100))); } @@ -66,22 +46,17 @@ public class BlockCloudDoor extends UDoor implements ICloudBlock { } @Override - public void onEntityCollision(World w, BlockPos pos, BlockState state, Entity entity) { + public void onEntityCollision(BlockState state, World w, BlockPos pos, Entity entity) { if (!applyBouncyness(state, entity)) { - super.onEntityCollision(w, pos, state, entity); + super.onEntityCollision(state, w, pos, entity); } } - @Override - public boolean canEntityDestroy(BlockState state, BlockView world, BlockPos pos, Entity entity) { - return getCanInteract(state, entity) && super.canEntityDestroy(state, world, pos, entity); - } - @Deprecated @Override - public float getPlayerRelativeBlockHardness(BlockState state, PlayerEntity player, World worldIn, BlockPos pos) { + public float calcBlockBreakingDelta(BlockState state, PlayerEntity player, BlockView worldIn, BlockPos pos) { if (CloudType.NORMAL.canInteract(player)) { - return super.getPlayerRelativeBlockHardness(state, player, worldIn, pos); + return super.calcBlockBreakingDelta(state, player, worldIn, pos); } return -1; } diff --git a/src/main/java/com/minelittlepony/unicopia/block/BlockCloudFence.java b/src/main/java/com/minelittlepony/unicopia/block/BlockCloudFence.java deleted file mode 100644 index 4a9d9e49..00000000 --- a/src/main/java/com/minelittlepony/unicopia/block/BlockCloudFence.java +++ /dev/null @@ -1,129 +0,0 @@ -package com.minelittlepony.unicopia.block; - -import java.util.List; - -import javax.annotation.Nullable; - -import com.minelittlepony.unicopia.CloudType; - -import net.minecraft.block.BlockRenderLayer; -import net.minecraft.block.BlockState; -import net.minecraft.block.FenceBlock; -import net.minecraft.entity.Entity; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.util.math.BlockPos; -import net.minecraft.util.math.Vec3d; -import net.minecraft.world.BlockView; -import net.minecraft.world.World; - -public class BlockCloudFence extends FenceBlock implements ICloudBlock { - - private final CloudType variant; - - public BlockCloudFence(Material material, CloudType variant, String domain, String name) { - super(material, material.getMaterialMapColor()); - setTranslationKey(name); - setRegistryName(domain, name); - - setHardness(0.5f); - setResistance(1.0F); - setLightOpacity(20); - setSoundType(SoundType.CLOTH); - useNeighborBrightness = true; - - this.variant = variant; - } - - @Override - public boolean isTranslucent(BlockState state) { - return variant == CloudType.NORMAL; - } - - @Override - public boolean isOpaqueCube(BlockState state) { - return false; - } - - @Override - public boolean isFullCube(BlockState state) { - return false; - } - - @Override - public boolean isAir(BlockState state, BlockView world, BlockPos pos) { - return allowsFallingBlockToPass(state, world, pos); - } - - @Override - public boolean isNormalCube(BlockState state) { - return false; - } - - @Override - public CloudType getCloudMaterialType(BlockState blockState) { - return variant; - } - - @Override - public BlockRenderLayer getRenderLayer() { - return BlockRenderLayer.TRANSLUCENT; - } - - @Override - public void onFallenUpon(World world, BlockPos pos, Entity entityIn, float fallDistance) { - if (!applyLanding(entityIn, fallDistance)) { - super.onFallenUpon(world, pos, entityIn, fallDistance); - } - } - - @Override - public void onEntityLand(BlockView world, Entity entity) { - if (!applyRebound(entity)) { - super.onEntityLand(world, entity); - } - } - - public boolean canConnectTo(BlockView world, BlockPos pos, Direction facing) { - BlockState myState = world.getBlockState(pos); - - return !(myState.getBlock() instanceof BlockCloudBanister) - && super.canConnectTo(world, pos, facing); - } - - @Override - public void onEntityCollision(BlockState state, World w, BlockPos pos, Entity entity) { - if (!applyBouncyness(state, entity)) { - super.onEntityCollision(state, w, pos, entity); - } - } - - @Override - public boolean canEntityDestroy(BlockState state, BlockView world, BlockPos pos, Entity entity) { - return getCanInteract(state, entity) && super.canEntityDestroy(state, world, pos, entity); - } - - @Deprecated - public void addCollisionBoxToList(BlockState state, World worldIn, BlockPos pos, Box entityBox, List collidingBoxes, @Nullable Entity entity, boolean isActualState) { - if (getCanInteract(state, entity)) { - super.addCollisionBoxToList(state, worldIn, pos, entityBox, collidingBoxes, entity, isActualState); - } - } - - @Deprecated - @Override - public float calcBlockBreakingDelta(BlockState state, PlayerEntity player, BlockView world, BlockPos pos) { - if (CloudType.NORMAL.canInteract(player)) { - return super.calcBlockBreakingDelta(state, player, world, pos); - } - return -1; - } - - @Deprecated - @Override - public RayTraceResult collisionRayTrace(BlockState state, World world, BlockPos pos, Vec3d start, Vec3d end) { - if (!handleRayTraceSpecialCases(world, pos, state)) { - return super.collisionRayTrace(state, world, pos, start, end); - } - return null; - } -} diff --git a/src/main/java/com/minelittlepony/unicopia/block/BlockCloudSlab.java b/src/main/java/com/minelittlepony/unicopia/block/BlockCloudSlab.java deleted file mode 100644 index b26f18c1..00000000 --- a/src/main/java/com/minelittlepony/unicopia/block/BlockCloudSlab.java +++ /dev/null @@ -1,147 +0,0 @@ -package com.minelittlepony.unicopia.block; - -import java.util.List; -import java.util.Random; - -import javax.annotation.Nullable; - -import com.minelittlepony.unicopia.CloudType; - -import net.minecraft.block.Block; -import net.minecraft.block.BlockState; -import net.minecraft.block.Material; -import net.minecraft.block.StairsBlock; -import net.minecraft.block.enums.BlockHalf; -import net.minecraft.entity.Entity; -import net.minecraft.item.Item; -import net.minecraft.state.property.Properties; -import net.minecraft.util.math.BlockPos; -import net.minecraft.util.math.Direction; -import net.minecraft.util.math.Vec3d; -import net.minecraft.world.World; - -public abstract class BlockCloudSlab extends USlab implements ICloudBlock { - - public BlockCloudSlab(T modelBlock, BlockCloudSlab single, Material material, String domain, String name) { - super(modelBlock, single, material, domain, name); - } - - @SuppressWarnings("deprecation") - @Override - public boolean isTopSolid(BlockState state) { - return getCloudMaterialType(state) == CloudType.ENCHANTED && super.isTopSolid(state); - } - - @SuppressWarnings("deprecation") - @FUF(reason = "...Really?") - public boolean isSideSolid(BlockState base_state, BlockAccess world, BlockPos pos, Direction side) { - return getCloudMaterialType(base_state) == CloudType.ENCHANTED && super.isSideSolid(base_state, world, pos, side); - } - - @Override - @Deprecated - public void addCollisionBoxToList(BlockState state, World worldIn, BlockPos pos, Box entityBox, List collidingBoxes, @Nullable Entity entity, boolean p_185477_7_) { - if (getCanInteract(state, entity)) { - super.addCollisionBoxToList(state, worldIn, pos, entityBox, collidingBoxes, entity, p_185477_7_); - } - } - - @Deprecated - @Override - public RayTraceResult collisionRayTrace(BlockState blockState, World worldIn, BlockPos pos, Vec3d start, Vec3d end) { - if (handleRayTraceSpecialCases(worldIn, pos, blockState)) { - return null; - } - return super.collisionRayTrace(blockState, worldIn, pos, start, end); - } - - @Override - public CloudType getCloudMaterialType(BlockState blockState) { - return modelBlock.getCloudMaterialType(blockState); - } - - public static class Single extends BlockCloudSlab { - - public final Double doubleSlab; - - public Single(T modelBlock, Material material, String domain, String name) { - super(modelBlock, null, material, domain, name); - - doubleSlab = new Double<>(this, domain, "double_" + name); - } - - @Override - public boolean isDouble() { - return false; - } - - @Override - public boolean isSideInvisible(BlockState state, BlockState beside, Direction face) { - - if (beside.getBlock() instanceof ICloudBlock) { - ICloudBlock cloud = ((ICloudBlock)beside.getBlock()); - - if (cloud.getCloudMaterialType(beside) == getCloudMaterialType(state)) { - - BlockHalf half = state.get(HALF); - - if (beside.getBlock() instanceof BlockCloudStairs) { - return beside.get(StairsBlock.HALF).ordinal() == state.get(HALF).ordinal() - && beside.get(Properties.FACING) == face; - } - - if (face == Direction.DOWN) { - return half == BlockHalf.BOTTOM; - } - - if (face == Direction.UP) { - return half == BlockHalf.TOP; - } - - if (beside.getBlock() == this) { - return beside.get(HALF) == state.get(HALF); - } - } - } - - return false; - } - } - - public static class Double extends BlockCloudSlab { - - public final Single singleSlab; - - public Double(Single single, String domain, String name) { - super(single.modelBlock, single, single.material, domain, name); - - this.singleSlab = single; - } - - @Override - public boolean isDouble() { - return true; - } - - @Override - public boolean doesSideBlockRendering(BlockState state, BlockView world, BlockPos pos, Direction face) { - - BlockState beside = world.getBlockState(pos.offset(face)); - - if (beside.getBlock() instanceof ICloudBlock) { - ICloudBlock cloud = ((ICloudBlock)beside.getBlock()); - - if (cloud.getCloudMaterialType(beside) == getCloudMaterialType(state)) { - return true; - } - } - - return false; - } - - @Override - public Item getItemDropped(BlockState state, Random rand, int fortune) { - return Item.getItemFromBlock(singleSlab); - } - } -} diff --git a/src/main/java/com/minelittlepony/unicopia/block/BlockCloudStairs.java b/src/main/java/com/minelittlepony/unicopia/block/BlockCloudStairs.java index de938c82..d8342af8 100644 --- a/src/main/java/com/minelittlepony/unicopia/block/BlockCloudStairs.java +++ b/src/main/java/com/minelittlepony/unicopia/block/BlockCloudStairs.java @@ -23,29 +23,8 @@ import net.minecraft.world.World; public class BlockCloudStairs extends UStairs implements ICloudBlock { - public BlockCloudStairs(BlockState inherited, String domain, String name) { - super(inherited, domain, name); - } - - @Override - public boolean isAir(BlockState state, BlockView world, BlockPos pos) { - return allowsFallingBlockToPass(state, world, pos); - } - - @Override - public void addCollisionBoxToList(BlockState state, World worldIn, BlockPos pos, Box entityBox, List collidingBoxes, @Nullable Entity entity, boolean p_185477_7_) { - if (getCanInteract(baseBlockState, entity)) { - super.addCollisionBoxToList(state, worldIn, pos, entityBox, collidingBoxes, entity, p_185477_7_); - } - } - - @Deprecated - @Override - public HitResult collisionRayTrace(BlockState blockState, World worldIn, BlockPos pos, Vec3d start, Vec3d end) { - if (handleRayTraceSpecialCases(worldIn, pos, blockState)) { - return null; - } - return super.collisionRayTrace(blockState, worldIn, pos, start, end); + public BlockCloudStairs(BlockState inherited) { + super(inherited); } @SuppressWarnings("deprecation") @@ -61,10 +40,7 @@ public class BlockCloudStairs extends UStairs implements ICloudBlock { } @Override - public boolean doesSideBlockRendering(BlockState state, BlockView world, BlockPos pos, Direction face) { - - BlockState beside = world.getBlockState(pos.offset(face)); - + public boolean isSideInvisible(BlockState state, BlockState beside, Direction face) { if (beside.getBlock() instanceof ICloudBlock) { ICloudBlock cloud = ((ICloudBlock)beside.getBlock()); @@ -97,7 +73,7 @@ public class BlockCloudStairs extends UStairs implements ICloudBlock { return sideIsBack || (sideIsSide && bsideIsSide && front == bfront && half == bhalf); - } else if (beside.getBlock() instanceof BlockCloudSlab) { + } else if (beside.getBlock() instanceof CloudSlabBlock) { SlabType bhalf = beside.get(SlabBlock.TYPE); if (face == Direction.UP || face == Direction.DOWN) { diff --git a/src/main/java/com/minelittlepony/unicopia/block/BlockDiamondDoor.java b/src/main/java/com/minelittlepony/unicopia/block/BlockDiamondDoor.java deleted file mode 100644 index 4f0051d4..00000000 --- a/src/main/java/com/minelittlepony/unicopia/block/BlockDiamondDoor.java +++ /dev/null @@ -1,48 +0,0 @@ -package com.minelittlepony.unicopia.block; - -import java.util.function.Supplier; - -import javax.annotation.Nullable; - -import com.minelittlepony.unicopia.EquinePredicates; - -import net.minecraft.block.SoundType; -import net.minecraft.block.material.MapColor; -import net.minecraft.block.material.Material; -import net.minecraft.block.state.BlockState; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.item.Item; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.BlockView; -import net.minecraft.world.World; - -public class BlockDiamondDoor extends UDoor { - - public BlockDiamondDoor(String domain, String name, Supplier theItem) { - super(Material.IRON, domain, name, theItem); - setSoundType(SoundType.METAL); - setHardness(5.0F); - } - - @Override - @Deprecated - public MapColor getMapColor(BlockState state, BlockView worldIn, BlockPos pos) { - return MapColor.DIAMOND; - } - - @Override - protected boolean canOpen(@Nullable PlayerEntity player) { - return EquinePredicates.MAGI.test(player); - } - - @Override - protected boolean onPowerStateChanged(World world, BlockState state, BlockPos pos, boolean powered) { - if (state.getValue(OPEN)) { - world.setBlockState(pos, state.with(OPEN, false), 2); - - return true; - } - - return false; - } -} diff --git a/src/main/java/com/minelittlepony/unicopia/block/BlockDutchDoor.java b/src/main/java/com/minelittlepony/unicopia/block/BlockDutchDoor.java deleted file mode 100644 index 9d9c5134..00000000 --- a/src/main/java/com/minelittlepony/unicopia/block/BlockDutchDoor.java +++ /dev/null @@ -1,110 +0,0 @@ -package com.minelittlepony.unicopia.block; - -import java.util.function.Supplier; - -import net.minecraft.block.BlockDoor; -import net.minecraft.block.material.Material; -import net.minecraft.block.state.BlockState; -import net.minecraft.item.Item; -import net.minecraft.util.Direction; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.BlockView; -import net.minecraft.world.World; - -public class BlockDutchDoor extends UDoor { - - public BlockDutchDoor(Material material, String domain, String name, Supplier theItem) { - super(material, domain, name, theItem); - } - - @Override - protected BlockPos getPrimaryDoorPos(BlockState state, BlockPos pos) { - return pos; - } - - @Override - public boolean isPassable(BlockView world, BlockPos pos) { - return world.getBlockState(pos).getValue(OPEN); - } - - @Override - protected boolean onPowerStateChanged(World world, BlockState state, BlockPos pos, boolean powered) { - boolean result = super.onPowerStateChanged(world, state, pos, powered); - - BlockState upper = world.getBlockState(pos.up()); - if (upper.getBlock() == this && upper.getValue(OPEN) != powered) { - world.setBlockState(pos.up(), upper.with(OPEN, powered)); - - return true; - } - - return result; - } - - // UPPER - HALF/HINGE/POWER{/OPEN} - // LOWER - HALF/FACING/FACING/OPEN - - @Override - public BlockState getActualState(BlockState state, BlockView world, BlockPos pos) { - - // copy properties in stored by the sibling block - if (state.getValue(HALF) == BlockDoor.EnumDoorHalf.LOWER) { - BlockState other = world.getBlockState(pos.up()); - - if (other.getBlock() == this) { - return state.with(HINGE, other.getValue(HINGE)) - .with(POWERED, other.getValue(POWERED)); - } - } else { - BlockState other = world.getBlockState(pos.down()); - - if (other.getBlock() == this) { - return state.with(FACING, other.getValue(FACING)); - } - } - - - return state; - } - - @Override - public BlockState getStateFromMeta(int meta) { - boolean upper = (meta & 8) != 0; - - BlockState state = getDefaultState() - .with(HALF, upper ? EnumDoorHalf.UPPER : EnumDoorHalf.LOWER) - .with(OPEN, (meta & 4) != 0); - - if (upper) { - return state.with(POWERED, (meta & 1) != 0) - .with(HINGE, (meta & 2) != 0 ? EnumHingePosition.RIGHT : EnumHingePosition.LEFT); - } - - return state.with(FACING, Direction.byHorizontalIndex(meta & 3).rotateYCCW()); - } - - @Override - public int getMetaFromState(BlockState state) { - int i = 0; - - if (state.getValue(HALF) == BlockDoor.EnumDoorHalf.UPPER) { - i |= 8; - - if (state.getValue(POWERED)) { - i |= 1; - } - - if (state.getValue(HINGE) == BlockDoor.EnumHingePosition.RIGHT) { - i |= 2; - } - } else { - i |= state.getValue(FACING).rotateY().getHorizontalIndex(); - } - - if (state.getValue(OPEN)) { - i |= 4; - } - - return i; - } -} diff --git a/src/main/java/com/minelittlepony/unicopia/block/BlockTomatoPlant.java b/src/main/java/com/minelittlepony/unicopia/block/BlockTomatoPlant.java index 32a6fb73..2f15c232 100644 --- a/src/main/java/com/minelittlepony/unicopia/block/BlockTomatoPlant.java +++ b/src/main/java/com/minelittlepony/unicopia/block/BlockTomatoPlant.java @@ -25,6 +25,7 @@ import net.minecraft.util.math.Direction; import net.minecraft.util.math.Vec3d; import net.minecraft.util.shape.VoxelShape; import net.minecraft.world.BlockView; +import net.minecraft.world.ViewableWorld; import net.minecraft.world.World; public class BlockTomatoPlant extends CropBlock { @@ -65,12 +66,13 @@ public class BlockTomatoPlant extends CropBlock { return UItems.tomato; } - public boolean canPlaceBlockAt(World world, BlockPos pos) { + @Override + public boolean canPlaceAt(BlockState state, ViewableWorld world, BlockPos pos) { if (world.getBlockState(pos.down()).getBlock() instanceof BlockTomatoPlant) { return true; } - return super.canPlaceBlockAt(world, pos); + return super.canPlaceAt(state, world, pos); } @Override diff --git a/src/main/java/com/minelittlepony/unicopia/block/CloudAnvilBlock.java b/src/main/java/com/minelittlepony/unicopia/block/CloudAnvilBlock.java new file mode 100644 index 00000000..5ca97065 --- /dev/null +++ b/src/main/java/com/minelittlepony/unicopia/block/CloudAnvilBlock.java @@ -0,0 +1,103 @@ +package com.minelittlepony.unicopia.block; + +import java.util.Random; + +import com.minelittlepony.unicopia.CloudType; +import com.minelittlepony.util.WorldEvent; + +import net.fabricmc.fabric.api.block.FabricBlockSettings; +import net.minecraft.block.AnvilBlock; +import net.minecraft.block.BlockRenderLayer; +import net.minecraft.block.BlockState; +import net.minecraft.block.Material; +import net.minecraft.entity.Entity; +import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.sound.BlockSoundGroup; +import net.minecraft.util.Hand; +import net.minecraft.util.hit.BlockHitResult; +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.BlockView; +import net.minecraft.world.World; + +public class CloudAnvilBlock extends AnvilBlock implements ICloudBlock { + @SuppressWarnings("deprecation") + public CloudAnvilBlock() { + super(FabricBlockSettings.of(Material.WOOL) + .strength(0.025F, 1) + .resistance(2000) + .breakByTool(net.fabricmc.fabric.api.tools.FabricToolTags.SHOVELS, 0) + .sounds(BlockSoundGroup.WOOL) + .ticksRandomly() + .build() + ); + } + + @Override + public BlockRenderLayer getRenderLayer() { + return BlockRenderLayer.TRANSLUCENT; + } + + @Override + public void onLandedUpon(World world, BlockPos pos, Entity entityIn, float fallDistance) { + if (!applyLanding(entityIn, fallDistance)) { + super.onLandedUpon(world, pos, entityIn, fallDistance); + } + } + + @Override + public void onLanding(World world, BlockPos pos, BlockState fallingState, BlockState hitState) { + WorldEvent.ENTITY_TAKEOFF.play(world, pos); + } + + @Override + public void onDestroyedOnLanding(World world, BlockPos pos) { + WorldEvent.ENTITY_TAKEOFF.play(world, pos); + } + + @Override + public boolean activate(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit) { + return false; + } + + @Override + public void onEntityLand(BlockView world, Entity entity) { + if (!applyRebound(entity)) { + super.onEntityLand(world, entity); + } + } + + @Override + public void onScheduledTick(BlockState state, World world, BlockPos pos, Random rand) { + BlockState below = world.getBlockState(pos.down()); + + if (below.getBlock() instanceof ICloudBlock) { + if (((ICloudBlock)below.getBlock()).isDense(below)) { + return; + } + } + + super.onScheduledTick(state, world, pos, rand); + } + + @Override + public void onEntityCollision(BlockState state, World w, BlockPos pos, Entity entity) { + if (!applyBouncyness(state, entity)) { + super.onEntityCollision(state, w, pos, entity); + } + } + + @Deprecated + @Override + public float calcBlockBreakingDelta(BlockState state, PlayerEntity player, BlockView world, BlockPos pos) { + if (!CloudType.NORMAL.canInteract(player)) { + return -1; + } + return super.calcBlockBreakingDelta(state, player, world, pos); + } + + + @Override + public CloudType getCloudMaterialType(BlockState blockState) { + return CloudType.NORMAL; + } +} diff --git a/src/main/java/com/minelittlepony/unicopia/block/CloudBanisterBlock.java b/src/main/java/com/minelittlepony/unicopia/block/CloudBanisterBlock.java new file mode 100644 index 00000000..f7bccf58 --- /dev/null +++ b/src/main/java/com/minelittlepony/unicopia/block/CloudBanisterBlock.java @@ -0,0 +1,57 @@ +package com.minelittlepony.unicopia.block; + +import java.util.List; + +import javax.annotation.Nullable; + +import com.minelittlepony.unicopia.CloudType; + +import net.minecraft.block.Block; +import net.minecraft.block.BlockRenderLayer; +import net.minecraft.block.BlockState; +import net.minecraft.block.Material; +import net.minecraft.entity.Entity; +import net.minecraft.util.math.Box; +import net.minecraft.util.math.Direction; +import net.minecraft.util.shape.VoxelShape; +import net.minecraft.util.shape.VoxelShapes; +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.BlockView; +import net.minecraft.world.World; + +public class CloudBanisterBlock extends CloudFenceBlock { + + public static final float l = 11; + public static final float d = 5; + public static final float h = 2; + + public static final Box SOUTH_AABB = new Box(d, 0, l, l, h, 1); + public static final Box WEST_AABB = new Box(0, 0, d, d, h, l); + public static final Box NORTH_AABB = new Box(d, 0, 0, l, h, d); + public static final Box EAST_AABB = new Box(l, 0, d, 1, h, l); + + public CloudBanisterBlock(Material material) { + super(material, CloudType.ENCHANTED); + this.collisionShapes = this.createShapes(l, d, h, 0.0F, d); + this.boundingShapes = this.createShapes(l, d, h, 0.0F, d); + } + + @Override + public BlockRenderLayer getRenderLayer() { + return BlockRenderLayer.SOLID; + } + + @Override + public boolean canConnect(BlockState myState, boolean bool, Direction facing) { + return myState.getBlock() instanceof CloudBanisterBlock + && super.canConnect(myState, bool, facing); + } + + @Override + public boolean canConnect(BlockView world, BlockPos pos, Direction facing) { + BlockState state = world.getBlockState(pos.offset(facing)); + + return state.getBlock() instanceof CloudBanisterBlock + && state.getMaterial() == world.getBlockState(pos).getMaterial(); + } +} diff --git a/src/main/java/com/minelittlepony/unicopia/block/BlockCloud.java b/src/main/java/com/minelittlepony/unicopia/block/CloudBlock.java similarity index 63% rename from src/main/java/com/minelittlepony/unicopia/block/BlockCloud.java rename to src/main/java/com/minelittlepony/unicopia/block/CloudBlock.java index cfc22e96..8d36b3a2 100644 --- a/src/main/java/com/minelittlepony/unicopia/block/BlockCloud.java +++ b/src/main/java/com/minelittlepony/unicopia/block/CloudBlock.java @@ -1,10 +1,7 @@ package com.minelittlepony.unicopia.block; -import java.util.List; import java.util.Random; -import javax.annotation.Nullable; - import com.minelittlepony.unicopia.CloudType; import com.minelittlepony.unicopia.SpeciesList; import com.minelittlepony.unicopia.UBlocks; @@ -19,18 +16,16 @@ import net.minecraft.entity.Entity; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.item.ItemStack; import net.minecraft.sound.BlockSoundGroup; -import net.minecraft.util.math.Box; import net.minecraft.util.math.Direction; import net.minecraft.util.math.BlockPos; -import net.minecraft.util.math.Vec3d; import net.minecraft.world.BlockView; import net.minecraft.world.World; -public class BlockCloud extends Block implements ICloudBlock, ITillable { +public class CloudBlock extends Block implements ICloudBlock, ITillable { private final CloudType variant; - public BlockCloud(Material material, CloudType variant, String domain, String name) { + public CloudBlock(Material material, CloudType variant) { super(FabricBlockSettings.of(material) .strength(0.5F, 1) .sounds(BlockSoundGroup.WOOL) @@ -69,7 +64,7 @@ public class BlockCloud extends Block implements ICloudBlock, ITillable { return variant == CloudType.NORMAL ? BlockRenderLayer.TRANSLUCENT : super.getRenderLayer(); } - @Deprecated + /*@Deprecated @Override public boolean isSideSolid(BlockState base_state, BlockView world, BlockPos pos, Direction side) { if (side == Direction.UP && (variant == CloudType.ENCHANTED || world.getBlockState(pos.up()).getBlock() instanceof ICloudBlock)) { @@ -77,13 +72,10 @@ public class BlockCloud extends Block implements ICloudBlock, ITillable { } return super.isSideSolid(base_state, world, pos, side); - } + }*/ @Override - public boolean doesSideBlockRendering(BlockState state, BlockView world, BlockPos pos, Direction face) { - - BlockState beside = world.getBlockState(pos.offset(face)); - + public boolean isSideInvisible(BlockState state, BlockState beside, Direction face) { if (beside.getBlock() instanceof ICloudBlock) { ICloudBlock cloud = ((ICloudBlock)beside.getBlock()); @@ -92,47 +84,35 @@ public class BlockCloud extends Block implements ICloudBlock, ITillable { } } - return super.doesSideBlockRendering(state, world, pos, face); + return super.isSideInvisible(state, beside, face); } @Override - public void onFallenUpon(World world, BlockPos pos, Entity entityIn, float fallDistance) { + public void onLandedUpon(World world, BlockPos pos, Entity entityIn, float fallDistance) { if (!applyLanding(entityIn, fallDistance)) { - super.onFallenUpon(world, pos, entityIn, fallDistance); + super.onLandedUpon(world, pos, entityIn, fallDistance); } } @Override - public void onLanded(World worldIn, Entity entity) { + public void onEntityLand(BlockView world, Entity entity) { if (!applyRebound(entity)) { - super.onLanded(worldIn, entity); + super.onEntityLand(world, entity); } } @Override - public void onEntityCollision(World w, BlockPos pos, BlockState state, Entity entity) { + public void onEntityCollision(BlockState state, World w, BlockPos pos, Entity entity) { if (!applyBouncyness(state, entity)) { - super.onEntityCollision(w, pos, state, entity); - } - } - - @Override - public boolean canEntityDestroy(BlockState state, BlockView world, BlockPos pos, Entity entity) { - return getCanInteract(state, entity) && super.canEntityDestroy(state, world, pos, entity); - } - - @Deprecated - public void addCollisionBoxToList(BlockState state, World worldIn, BlockPos pos, Box entityBox, List collidingBoxes, @Nullable Entity entity, boolean p_185477_7_) { - if (getCanInteract(state, entity)) { - super.addCollisionBoxToList(state, worldIn, pos, entityBox, collidingBoxes, entity, p_185477_7_); + super.onEntityCollision(state, w, pos, entity); } } @Deprecated @Override - public float getPlayerRelativeBlockHardness(BlockState state, PlayerEntity player, World worldIn, BlockPos pos) { + public float calcBlockBreakingDelta(BlockState state, PlayerEntity player, BlockView worldIn, BlockPos pos) { if (CloudType.NORMAL.canInteract(player)) { - return super.getPlayerRelativeBlockHardness(state, player, worldIn, pos); + return super.calcBlockBreakingDelta(state, player, worldIn, pos); } return -1; } @@ -142,15 +122,6 @@ public class BlockCloud extends Block implements ICloudBlock, ITillable { return variant; } - @Deprecated - @Override - public RayTraceResult collisionRayTrace(BlockState blockState, World worldIn, BlockPos pos, Vec3d start, Vec3d end) { - if (!handleRayTraceSpecialCases(worldIn, pos, blockState)) { - return super.collisionRayTrace(blockState, worldIn, pos, start, end); - } - return null; - } - @Override public boolean canBeTilled(ItemStack hoe, PlayerEntity player, World world, BlockState state, BlockPos pos) { return SpeciesList.instance().getPlayer(player).getSpecies().canInteractWithClouds() diff --git a/src/main/java/com/minelittlepony/unicopia/block/CloudFenceBlock.java b/src/main/java/com/minelittlepony/unicopia/block/CloudFenceBlock.java new file mode 100644 index 00000000..1fdc46a7 --- /dev/null +++ b/src/main/java/com/minelittlepony/unicopia/block/CloudFenceBlock.java @@ -0,0 +1,87 @@ +package com.minelittlepony.unicopia.block; + +import com.minelittlepony.unicopia.CloudType; + +import net.fabricmc.fabric.api.block.FabricBlockSettings; +import net.minecraft.block.BlockRenderLayer; +import net.minecraft.block.BlockState; +import net.minecraft.block.FenceBlock; +import net.minecraft.block.Material; +import net.minecraft.entity.Entity; +import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.sound.BlockSoundGroup; +import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.Direction; +import net.minecraft.world.BlockView; +import net.minecraft.world.World; + +public class CloudFenceBlock extends FenceBlock implements ICloudBlock { + + private final CloudType variant; + + public CloudFenceBlock(Material material, CloudType variant) { + super(FabricBlockSettings.of(material) + .hardness(0.5F) + .resistance(1) + .sounds(BlockSoundGroup.WOOL) + .build()); + + this.variant = variant; + } + + @Override + public boolean isTranslucent(BlockState state, BlockView world, BlockPos pos) { + return variant == CloudType.NORMAL; + } + + @Override + public boolean isOpaque(BlockState state) { + return false; + } + + @Override + public CloudType getCloudMaterialType(BlockState blockState) { + return variant; + } + + @Override + public BlockRenderLayer getRenderLayer() { + return BlockRenderLayer.TRANSLUCENT; + } + + @Override + public void onLandedUpon(World world, BlockPos pos, Entity entityIn, float fallDistance) { + if (!applyLanding(entityIn, fallDistance)) { + super.onLandedUpon(world, pos, entityIn, fallDistance); + } + } + + @Override + public void onEntityLand(BlockView world, Entity entity) { + if (!applyRebound(entity)) { + super.onEntityLand(world, entity); + } + } + + @Override + public boolean canConnect(BlockState state, boolean bool, Direction facing) { + return !(state.getBlock() instanceof CloudBanisterBlock) + && super.canConnect(state, bool, facing); + } + + @Override + public void onEntityCollision(BlockState state, World w, BlockPos pos, Entity entity) { + if (!applyBouncyness(state, entity)) { + super.onEntityCollision(state, w, pos, entity); + } + } + + @Deprecated + @Override + public float calcBlockBreakingDelta(BlockState state, PlayerEntity player, BlockView world, BlockPos pos) { + if (CloudType.NORMAL.canInteract(player)) { + return super.calcBlockBreakingDelta(state, player, world, pos); + } + return -1; + } +} diff --git a/src/main/java/com/minelittlepony/unicopia/block/CloudSlabBlock.java b/src/main/java/com/minelittlepony/unicopia/block/CloudSlabBlock.java new file mode 100644 index 00000000..f6e40232 --- /dev/null +++ b/src/main/java/com/minelittlepony/unicopia/block/CloudSlabBlock.java @@ -0,0 +1,69 @@ +package com.minelittlepony.unicopia.block; + +import com.minelittlepony.unicopia.CloudType; + +import net.fabricmc.fabric.api.block.FabricBlockSettings; +import net.minecraft.block.Block; +import net.minecraft.block.BlockState; +import net.minecraft.block.Material; +import net.minecraft.block.StairsBlock; +import net.minecraft.block.enums.SlabType; +import net.minecraft.state.property.Properties; +import net.minecraft.util.math.Direction; + +public class CloudSlabBlock extends USlab implements ICloudBlock { + + public CloudSlabBlock(T modelBlock, Material material) { + super(modelBlock, FabricBlockSettings.of(material).build()); + } + + @Override + public CloudType getCloudMaterialType(BlockState blockState) { + return modelBlock.getCloudMaterialType(blockState); + } + + @Override + public boolean isSideInvisible(BlockState state, BlockState beside, Direction face) { + if (isDouble(state)) { + if (beside.getBlock() instanceof ICloudBlock) { + ICloudBlock cloud = ((ICloudBlock)beside.getBlock()); + + if (cloud.getCloudMaterialType(beside) == getCloudMaterialType(state)) { + return true; + } + } + + return false; + } else { + if (beside.getBlock() instanceof ICloudBlock) { + ICloudBlock cloud = ((ICloudBlock)beside.getBlock()); + + if (cloud.getCloudMaterialType(beside) == getCloudMaterialType(state)) { + + SlabType half = state.get(TYPE); + + if (beside.getBlock() instanceof BlockCloudStairs) { + return beside.get(StairsBlock.HALF).ordinal() == state.get(TYPE).ordinal() + && beside.get(Properties.FACING) == face; + } + + if (face == Direction.DOWN) { + return half == SlabType.BOTTOM; + } + + if (face == Direction.UP) { + return half == SlabType.TOP; + } + + if (beside.getBlock() == this) { + return beside.get(TYPE) == state.get(TYPE); + } + } + } + } + + return false; + } + + +} diff --git a/src/main/java/com/minelittlepony/unicopia/block/DiamondDoorBlock.java b/src/main/java/com/minelittlepony/unicopia/block/DiamondDoorBlock.java new file mode 100644 index 00000000..25f1c4b9 --- /dev/null +++ b/src/main/java/com/minelittlepony/unicopia/block/DiamondDoorBlock.java @@ -0,0 +1,40 @@ +package com.minelittlepony.unicopia.block; + +import javax.annotation.Nullable; + +import com.minelittlepony.unicopia.EquinePredicates; + +import net.fabricmc.fabric.api.block.FabricBlockSettings; +import net.minecraft.block.BlockState; +import net.minecraft.block.Material; +import net.minecraft.block.MaterialColor; +import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.sound.BlockSoundGroup; +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.World; + +public class DiamondDoorBlock extends AbstractDoorBlock { + public DiamondDoorBlock() { + super(FabricBlockSettings.of(Material.METAL) + .sounds(BlockSoundGroup.METAL) + .materialColor(MaterialColor.DIAMOND) + .hardness(5) + .build()); + } + + @Override + protected boolean canOpen(@Nullable PlayerEntity player) { + return EquinePredicates.MAGI.test(player); + } + + @Override + protected boolean onPowerStateChanged(World world, BlockState state, BlockPos pos, boolean powered) { + if (state.get(OPEN)) { + world.setBlockState(pos, state.with(OPEN, false), 2); + + return true; + } + + return false; + } +} diff --git a/src/main/java/com/minelittlepony/unicopia/block/DutchDoorBlock.java b/src/main/java/com/minelittlepony/unicopia/block/DutchDoorBlock.java new file mode 100644 index 00000000..22fb39e0 --- /dev/null +++ b/src/main/java/com/minelittlepony/unicopia/block/DutchDoorBlock.java @@ -0,0 +1,56 @@ +package com.minelittlepony.unicopia.block; + +import net.minecraft.block.BlockState; +import net.minecraft.block.enums.DoubleBlockHalf; +import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.Direction; +import net.minecraft.world.IWorld; +import net.minecraft.world.World; + +public class DutchDoorBlock extends AbstractDoorBlock { + + public DutchDoorBlock(Settings settings) { + super(settings); + } + + @Override + protected BlockPos getPrimaryDoorPos(BlockState state, BlockPos pos) { + return pos; + } + + @Override + protected boolean onPowerStateChanged(World world, BlockState state, BlockPos pos, boolean powered) { + boolean result = super.onPowerStateChanged(world, state, pos, powered); + + BlockState upper = world.getBlockState(pos.up()); + if (upper.getBlock() == this && upper.get(OPEN) != powered) { + world.setBlockState(pos.up(), upper.with(OPEN, powered)); + + return true; + } + + return result; + } + + // UPPER - HALF/HINGE/POWER{/OPEN} + // LOWER - HALF/FACING/FACING/OPEN + + @Override + public BlockState getStateForNeighborUpdate(BlockState state, Direction face, BlockState other, IWorld world, BlockPos pos, BlockPos otherPos) { + + // copy properties in stored by the sibling block + if (state.get(HALF) == DoubleBlockHalf.LOWER) { + if (other.getBlock() == this) { + return state.with(HINGE, other.get(HINGE)) + .with(POWERED, other.get(POWERED)); + } + } else { + if (other.getBlock() == this) { + return state.with(FACING, other.get(FACING)); + } + } + + + return state; + } +} diff --git a/src/main/java/com/minelittlepony/unicopia/block/GlowingGemBlock.java b/src/main/java/com/minelittlepony/unicopia/block/GlowingGemBlock.java index 62144b8a..dd23838f 100644 --- a/src/main/java/com/minelittlepony/unicopia/block/GlowingGemBlock.java +++ b/src/main/java/com/minelittlepony/unicopia/block/GlowingGemBlock.java @@ -53,7 +53,7 @@ public class GlowingGemBlock extends TorchBlock implements ICloudBlock { protected static final VoxelShape TORCH_WEST_AABB = VoxelShapes.cuboid(new Box(F, E, B, 1, 1, C)); protected static final VoxelShape TORCH_EAST_AABB = VoxelShapes.cuboid(new Box(0, E, B, A, 1, C)); - public GlowingGemBlock(String domain, String name) { + public GlowingGemBlock() { super(FabricBlockSettings.of(Material.PART) .noCollision() .strength(0, 0) diff --git a/src/main/java/com/minelittlepony/unicopia/block/ICloudBlock.java b/src/main/java/com/minelittlepony/unicopia/block/ICloudBlock.java index 7592b511..f96a4b87 100644 --- a/src/main/java/com/minelittlepony/unicopia/block/ICloudBlock.java +++ b/src/main/java/com/minelittlepony/unicopia/block/ICloudBlock.java @@ -2,7 +2,8 @@ package com.minelittlepony.unicopia.block; import com.minelittlepony.unicopia.CloudType; import com.minelittlepony.unicopia.EquinePredicates; -import com.minelittlepony.unicopia.UClient; +import com.minelittlepony.unicopia.InteractionManager; + import net.minecraft.block.BedBlock; import net.minecraft.block.Block; import net.minecraft.block.BlockState; @@ -25,7 +26,7 @@ public interface ICloudBlock { default boolean handleRayTraceSpecialCases(World world, BlockPos pos, BlockState state) { if (world.isClient) { - PlayerEntity player = UClient.instance().getPlayer(); + PlayerEntity player = InteractionManager.instance().getClientPlayer(); if (player.abilities.creativeMode) { return false; diff --git a/src/main/java/com/minelittlepony/unicopia/block/ITreeGen.java b/src/main/java/com/minelittlepony/unicopia/block/ITreeGen.java deleted file mode 100644 index 47b536c2..00000000 --- a/src/main/java/com/minelittlepony/unicopia/block/ITreeGen.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.minelittlepony.unicopia.block; - -import net.minecraft.block.BlockState; -import net.minecraft.world.World; - -@FunctionalInterface -public interface ITreeGen { - WorldGenAbstractTree getTreeGen(World world, BlockState state, boolean massive); - - default boolean canGrowMassive() { - return false; - } -} \ No newline at end of file diff --git a/src/main/java/com/minelittlepony/unicopia/block/UDoor.java b/src/main/java/com/minelittlepony/unicopia/block/UDoor.java deleted file mode 100644 index 34d69003..00000000 --- a/src/main/java/com/minelittlepony/unicopia/block/UDoor.java +++ /dev/null @@ -1,199 +0,0 @@ -package com.minelittlepony.unicopia.block; - -import java.util.Random; -import java.util.function.Supplier; - -import javax.annotation.Nullable; - -import com.minelittlepony.util.WorldEvent; - -import net.minecraft.block.Block; -import net.minecraft.block.BlockState; -import net.minecraft.block.DoorBlock; -import net.minecraft.block.Material; -import net.minecraft.block.enums.DoubleBlockHalf; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.item.Item; -import net.minecraft.item.ItemStack; -import net.minecraft.item.Items; -import net.minecraft.util.Hand; -import net.minecraft.util.hit.BlockHitResult; -import net.minecraft.util.math.BlockPos; -import net.minecraft.util.math.Direction; -import net.minecraft.world.World; - -public abstract class UDoor extends DoorBlock { - - private final Supplier theItem; - - protected UDoor(Material material, String domain, String name, Supplier theItem) { - super(material); - disableStats(); - setTranslationKey(name); - setRegistryName(domain, name); - - this.theItem = theItem; - } - - @Override - public Block setSoundType(SoundType sound) { - return super.setSoundType(sound); - } - - @Override - public Item getItemDropped(BlockState state, Random rand, int fortune) { - return state.getValue(HALF) == BlockDoor.EnumDoorHalf.UPPER ? Items.AIR : getItem(); - } - - @Override - public ItemStack getItem(World world, BlockPos pos, BlockState state) { - return new ItemStack(getItem()); - } - - protected Item getItem() { - return theItem.get(); - } - - protected WorldEvent getCloseSound() { - return isLockable() ? WorldEvent.IRON_DOOR_SLAM : WorldEvent.WOODEN_DOOR_SLAM; - } - - protected WorldEvent getOpenSound() { - return isLockable() ? WorldEvent.IRON_DOOR_OPEN : WorldEvent.WOODEN_DOOR_OPEN; - } - - @Override - public boolean activate(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit) { - return toggleDoor(world, pos, false, true, player); - } - - @Override - public void setOpen(World world, BlockPos pos, boolean open) { - toggleDoor(world, pos, open, false, null); - } - - protected boolean isLockable() { - return material == Material.METAL; - } - - protected boolean canBePowered() { - return true; - } - - protected boolean canOpen(@Nullable PlayerEntity player) { - return player == null || material != Material.METAL; - } - - protected boolean toggleDoor(World world, BlockPos pos, boolean open, boolean force, @Nullable PlayerEntity player) { - if (!canOpen(player)) { - return false; - } - - BlockState state = world.getBlockState(pos); - - if (state.getBlock() != this) { - return false; - } - - BlockPos lower = getPrimaryDoorPos(state, pos); - - BlockState mainDoor = pos == lower ? state : world.getBlockState(lower); - - if (mainDoor.getBlock() != this) { - return false; - } - - if (!force && mainDoor.get(OPEN) == open) { - return false; - } - - state = mainDoor.cycle(OPEN); - - world.setBlockState(lower, state, 10); - - world.markBlockRangeForRenderUpdate(lower, pos); - - WorldEvent sound = state.getValue(OPEN) ? getOpenSound() : getCloseSound(); - - world.playEvent(player, sound.getId(), pos, 0); - - return true; - } - - protected BlockPos getPrimaryDoorPos(BlockState state, BlockPos pos) { - return state.get(HALF) == DoubleBlockHalf.LOWER ? pos : pos.down(); - } - - @Override - public void neighborUpdate(BlockState state, World world, BlockPos pos, Block sender, BlockPos fromPos, boolean v) { - if (state.get(HALF) == DoubleBlockHalf.UPPER) { - BlockPos lower = pos.down(); - - BlockState lowerDoor = world.getBlockState(lower); - - // pop us off if we don't have a lower door - if (lowerDoor.getBlock() != this) { - world.breakBlock(pos, true); - } else if (sender != this) { - lowerDoor.neighborUpdate(world, lower, sender, fromPos, v); - } - - return; - } - - boolean destroyed = false; - - BlockPos upper = pos.up(); - BlockState upperDoor = world.getBlockState(upper); - - // pop us off if we don't have an upper door - if (upperDoor.getBlock() != this) { - world.breakBlock(pos, true); - destroyed = true; - } - - // pop us off if we don't have support - if (!world.getBlockState(pos.down()).hasSolidTopSurface(world, pos.down(), null)) { - world.breakBlock(pos, true); - - destroyed = true; - - if (upperDoor.getBlock() == this) { - world.breakBlock(upper, true); - } - } - - if (destroyed) { - if (!world.isClient) { - dropBlockAsItem(world, pos, state, 0); - } - } else if (canBePowered()) { - boolean powered = world.isReceivingRedstonePower(pos) || world.isReceivingRedstonePower(upper); - - if (sender != this && (powered || sender.getDefaultState().emitsRedstonePower()) && powered != upperDoor.get(POWERED)) { - world.setBlockState(upper, upperDoor.with(POWERED, powered), 2); - - if (onPowerStateChanged(world, state, pos, powered)) { - world.markBlockRangeForRenderUpdate(pos, upper); - - WorldEvent sound = powered ? getOpenSound() : getCloseSound(); - - world.playGlobalEvent(null, sound.getId(), pos, 0); - } - } - } - } - - /** - * Called by the lower block when the powered state changes. - */ - protected boolean onPowerStateChanged(World world, BlockState state, BlockPos pos, boolean powered) { - if (powered != state.get(OPEN)) { - world.setBlockState(pos, state.with(OPEN, powered), 2); - - return true; - } - - return false; - } -} diff --git a/src/main/java/com/minelittlepony/unicopia/block/UPot.java b/src/main/java/com/minelittlepony/unicopia/block/UPot.java index 07149169..48b3e924 100644 --- a/src/main/java/com/minelittlepony/unicopia/block/UPot.java +++ b/src/main/java/com/minelittlepony/unicopia/block/UPot.java @@ -11,9 +11,7 @@ import net.minecraft.world.World; public class UPot extends FlowerPotBlock { - public UPot(String domain, String name) { - setTranslationKey(name); - setRegistryName(domain, name); + public UPot() { setHardness(0); setSoundType(SoundType.STONE); } diff --git a/src/main/java/com/minelittlepony/unicopia/block/USapling.java b/src/main/java/com/minelittlepony/unicopia/block/USapling.java deleted file mode 100644 index d8d995f4..00000000 --- a/src/main/java/com/minelittlepony/unicopia/block/USapling.java +++ /dev/null @@ -1,159 +0,0 @@ -package com.minelittlepony.unicopia.block; - -import java.util.Random; - -import javax.annotation.Nullable; - -import com.minelittlepony.util.LenientState; - -import net.minecraft.block.BlockPlanks; -import net.minecraft.block.BlockSapling; -import net.minecraft.block.SoundType; -import net.minecraft.block.state.BlockStateContainer; -import net.minecraft.block.state.BlockState; -import net.minecraft.creativetab.CreativeTabs; -import net.minecraft.init.Blocks; -import net.minecraft.item.ItemStack; -import net.minecraft.util.NonNullList; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.World; -import net.minecraft.world.gen.feature.WorldGenAbstractTree; - -public class USapling extends BlockSapling implements ITreeGen { - - private ITreeGen treeGen; - - public USapling(String domain, String name) { - setRegistryName(domain, name); - setTranslationKey(name); - setSoundType(SoundType.PLANT); - - setDefaultState(stateFactory.getDefaultState().with(STAGE, 0)); - } - - public USapling setTreeGen(ITreeGen gen) { - treeGen = gen; - - return this; - } - - @Override - public void generateTree(World world, BlockPos pos, BlockState state, Random rand) { - - boolean massive = canGrowMassive(); - - BlockPos i = massive ? findTwoByTwoSpace(world, pos, state) : pos; - - if (i == null) { - massive = false; - i = BlockPos.ORIGIN; - } - - // remove the sapling and any contributing siblings before growing the tree - setSaplingsState(world, Blocks.AIR.getDefaultState(), massive, i); - - if (!getTreeGen(world, state, massive).generate(world, rand, i)) { - // place them back if tree growth failed - setSaplingsState(world, state, massive, i); - } - } - - @Override - public void getSubBlocks(CreativeTabs tab, NonNullList items) { - items.add(new ItemStack(this)); - } - - protected void setSaplingsState(World world, BlockState state, boolean massive, BlockPos pos) { - if (massive) { - world.setBlockState(pos , state, 4); - world.setBlockState(pos.add(1, 0, 0), state, 4); - world.setBlockState(pos.add(0, 0, 1), state, 4); - world.setBlockState(pos.add(1, 0, 1), state, 4); - } else { - world.setBlockState(pos, state, 4); - } - } - - @Override - public WorldGenAbstractTree getTreeGen(World world, BlockState state, boolean massive) { - return treeGen.getTreeGen(world, state, massive); - } - - @Override - public boolean canGrowMassive() { - return treeGen.canGrowMassive(); - } - - /** - * Looks for a suitable 2x2 space that a tree can grow in. - * Returns null if no such spaces were found. - */ - @Nullable - public BlockPos findTwoByTwoSpace(World world, BlockPos pos, BlockState state) { - BlockPos xNegP = pos.add(-1, 0, 0); - BlockPos xPosP = pos.add( 1, 0, 0); - - BlockPos zNegP = pos.add( 0, 0, -1); - BlockPos zPosP = pos.add( 0, 0, 1); - - boolean xNeg = isMatch(state, world.getBlockState(xNegP)); - boolean xPos = isMatch(state, world.getBlockState(xPosP)); - - boolean zNeg = isMatch(state, world.getBlockState(zNegP)); - boolean zPos = isMatch(state, world.getBlockState(zPosP)); - - if (xNeg && zNeg) { - BlockPos corner = pos.add(-1, 0, -1); - - if (isMatch(state, world.getBlockState(corner))) { - return corner; - } - } - - if (xNeg && zPos && isMatch(state, world.getBlockState(pos.add(-1, 0, 1)))) { - return xNegP; - } - - if (xPos && zNeg && isMatch(state, world.getBlockState(pos.add(1, 0, -1)))) { - return pos; - } - - if (xPos && zPos && isMatch(state, world.getBlockState(pos.add(-1, 0, 1)))) { - return zNegP; - } - - return null; - } - - protected boolean isMatch(BlockState state, BlockState other) { - return other.getBlock() == this; - } - - @Deprecated - @Override - public boolean isTypeAt(World world, BlockPos pos, BlockPlanks.EnumType type) { - return world.getBlockState(pos).getBlock() == this; - } - - @Override - public int damageDropped(BlockState state) { - return 0; - } - - @Override - public BlockState getStateFromMeta(int meta) { - return getDefaultState().with(STAGE, (meta & 8) >> 3); - } - - @Override - public int getMetaFromState(BlockState state) { - int i = 0; - i |= state.getValue(STAGE) << 3; - return i; - } - - @Override - protected BlockStateContainer createBlockState() { - return new LenientState(this, STAGE); - } -} diff --git a/src/main/java/com/minelittlepony/unicopia/client/ClientHooks.java b/src/main/java/com/minelittlepony/unicopia/client/ClientHooks.java index 921370bf..d4dde396 100644 --- a/src/main/java/com/minelittlepony/unicopia/client/ClientHooks.java +++ b/src/main/java/com/minelittlepony/unicopia/client/ClientHooks.java @@ -1,8 +1,8 @@ package com.minelittlepony.unicopia.client; +import com.minelittlepony.unicopia.InteractionManager; import com.minelittlepony.unicopia.SpeciesList; import com.minelittlepony.unicopia.UBlocks; -import com.minelittlepony.unicopia.UClient; import com.minelittlepony.unicopia.UItems; import com.minelittlepony.unicopia.client.gui.UHud; import com.minelittlepony.unicopia.entity.capabilities.ICamera; @@ -17,24 +17,24 @@ class ClientHooks { public static void postEntityRender() { GlStateManager.enableAlphaTest(); - UClient.instance().postRenderEntity(event.getEntity()); + InteractionManager.instance().postRenderEntity(event.getEntity()); } public static void preEntityRender() { - if (UClient.instance().renderEntity(event.getEntity(), event.getPartialRenderTick())) { + if (InteractionManager.instance().renderEntity(event.getEntity(), event.getPartialRenderTick())) { event.setCanceled(true); } } public static void onDisplayGui(GuiScreenEvent.InitGuiEvent.Post event) { if (event.getGui() instanceof GuiOptions || event.getGui() instanceof GuiShareToLan) { - UnicopiaClient.addUniButton(event.getButtonList()); + ClientInteractionManager.addUniButton(event.getButtonList()); } } public static void onGameTick(TickEvent.ClientTickEvent event) { if (event.phase == Phase.END) { - UClient.instance().tick(); + InteractionManager.instance().tick(); } } @@ -42,7 +42,7 @@ class ClientHooks { GlStateManager.pushMatrix(); if (event.getType() != ElementType.ALL) { - IPlayer player = UClient.instance().getIPlayer(); + IPlayer player = InteractionManager.instance().getIPlayer(); if (player != null && MinecraftClient.getInstance().world != null) { UHud.instance.repositionElements(player, event.getResolution(), event.getType(), true); @@ -59,7 +59,7 @@ class ClientHooks { public static void postRenderHud(RenderGameOverlayEvent.Post event) { if (event.getType() == ElementType.ALL) { - IPlayer player = UClient.instance().getIPlayer(); + IPlayer player = InteractionManager.instance().getIPlayer(); if (player != null && MinecraftClient.getInstance().world != null) { UHud.instance.renderHud(player, event.getResolution()); @@ -80,7 +80,7 @@ class ClientHooks { public static void setupPlayerCamera(EntityViewRenderEvent.CameraSetup event) { - IPlayer player = UClient.instance().getIPlayer(); + IPlayer player = InteractionManager.instance().getIPlayer(); if (player != null) { ICamera view = player.getCamera(); diff --git a/src/main/java/com/minelittlepony/unicopia/client/UnicopiaClient.java b/src/main/java/com/minelittlepony/unicopia/client/ClientInteractionManager.java similarity index 79% rename from src/main/java/com/minelittlepony/unicopia/client/UnicopiaClient.java rename to src/main/java/com/minelittlepony/unicopia/client/ClientInteractionManager.java index 1372c419..e1db7df6 100644 --- a/src/main/java/com/minelittlepony/unicopia/client/UnicopiaClient.java +++ b/src/main/java/com/minelittlepony/unicopia/client/ClientInteractionManager.java @@ -9,8 +9,9 @@ import javax.annotation.Nullable; import com.minelittlepony.unicopia.MineLP; import com.minelittlepony.unicopia.Race; import com.minelittlepony.unicopia.SpeciesList; -import com.minelittlepony.unicopia.UClient; +import com.minelittlepony.unicopia.ServerInteractionManager; import com.minelittlepony.unicopia.Config; +import com.minelittlepony.unicopia.InteractionManager; import com.minelittlepony.unicopia.UEntities; import com.minelittlepony.unicopia.UParticles; import com.minelittlepony.unicopia.Unicopia; @@ -19,17 +20,22 @@ import com.minelittlepony.unicopia.client.gui.SettingsScreen; import com.minelittlepony.unicopia.client.input.Keyboard; import com.minelittlepony.unicopia.client.input.MouseControl; import com.minelittlepony.unicopia.entity.capabilities.IPlayer; +import com.minelittlepony.unicopia.inventory.gui.GuiOfHolding; import com.minelittlepony.unicopia.client.input.InversionAwareKeyboardInput; import com.minelittlepony.unicopia.network.MsgRequestCapabilities; +import com.minelittlepony.util.dummy.DummyClientPlayerEntity; import com.mojang.authlib.GameProfile; +import com.mojang.blaze3d.platform.GlStateManager; import net.minecraft.client.MinecraftClient; import net.minecraft.client.input.Input; import net.minecraft.client.network.ClientPlayerEntity; +import net.minecraft.container.ContainerType; +import net.minecraft.container.NameableContainerProvider; import net.minecraft.entity.Entity; import net.minecraft.entity.player.PlayerEntity; -public class UnicopiaClient extends UClient { +public class ClientInteractionManager extends ServerInteractionManager { /** * The race preferred by the client - as determined by mine little pony. @@ -55,52 +61,41 @@ public class UnicopiaClient extends UClient { return Config.instance().getPrefferedRace(); } - @Override - public void displayGuiToPlayer(PlayerEntity player, IInteractionObject inventory) { - if (player instanceof PlayerEntitySP) { - if ("unicopia:itemofholding".equals(inventory.getGuiID())) { - MinecraftClient.getInstance().displayGuiScreen(new GuiOfHolding(inventory)); - } - } else { - super.displayGuiToPlayer(player, inventory); - } - } - @Override @Nullable - public PlayerEntity getPlayer() { + public PlayerEntity getClientPlayer() { return MinecraftClient.getInstance().player; } @Override @Nullable public PlayerEntity getPlayerByUUID(UUID playerId) { - Minecraft mc = MinecraftClient.getInstance(); + MinecraftClient mc = MinecraftClient.getInstance(); - if (mc.player.getUniqueID().equals(playerId)) { + if (mc.player.getUuid().equals(playerId)) { return mc.player; } - return mc.world.getPlayerEntityByUUID(playerId); + return mc.world.getPlayerByUuid(playerId); } @Override @Nonnull public PlayerEntity createPlayer(Entity observer, GameProfile profile) { - return new EntityFakeClientPlayer(observer.world, profile); + return new DummyClientPlayerEntity(observer.world, profile); } @Override public boolean isClientPlayer(@Nullable PlayerEntity player) { - if (getPlayer() == player) { + if (getClientPlayer() == player) { return true; } - if (getPlayer() == null || player == null) { + if (getClientPlayer() == null || player == null) { return false; } - return IPlayer.equal(getPlayer(), player); + return IPlayer.equal(getClientPlayer(), player); } @Override @@ -115,9 +110,9 @@ public class UnicopiaClient extends UClient { if (iplayer.getGravity().getGravitationConstant() < 0) { GlStateManager.translate(0, entity.height, 0); - GlStateManager.scale(1, -1, 1); - entity.prevRotationPitch *= -1; - entity.rotationPitch *= -1; + GlStateManager.scalef(1, -1, 1); + entity.prevPitch *= -1; + entity.pitch *= -1; } } } @@ -133,10 +128,10 @@ public class UnicopiaClient extends UClient { IPlayer iplayer = SpeciesList.instance().getPlayer((PlayerEntity)entity); if (iplayer.getGravity().getGravitationConstant() < 0) { - GlStateManager.scale(1, -1, 1); + GlStateManager.scalef(1, -1, 1); GlStateManager.translate(0, -entity.height, 0); - entity.prevRotationPitch *= -1; - entity.rotationPitch *= -1; + entity.prevPitch *= -1; + entity.pitch *= -1; } if (DisguiseRenderer.getInstance().renderDisguiseToGui(iplayer)) { @@ -164,7 +159,7 @@ public class UnicopiaClient extends UClient { @Override public void tick() { - PlayerEntity player = UClient.instance().getPlayer(); + PlayerEntity player = InteractionManager.instance().getClientPlayer(); if (player != null && !player.removed) { Race newRace = getclientPlayerRace(); diff --git a/src/main/java/com/minelittlepony/unicopia/client/UParticles.java b/src/main/java/com/minelittlepony/unicopia/client/UParticles.java deleted file mode 100644 index 770807d3..00000000 --- a/src/main/java/com/minelittlepony/unicopia/client/UParticles.java +++ /dev/null @@ -1,22 +0,0 @@ -package com.minelittlepony.unicopia.client; - -import com.minelittlepony.unicopia.client.particle.ParticleChangelingMagic; -import com.minelittlepony.unicopia.client.particle.ParticleDisk; -import com.minelittlepony.unicopia.client.particle.ParticleRaindrops; -import com.minelittlepony.unicopia.client.particle.ParticleSphere; -import com.minelittlepony.unicopia.client.particle.ParticleUnicornMagic; - -import net.fabricmc.api.EnvType; -import net.fabricmc.api.Environment; -import net.minecraft.particle.DefaultParticleType; -import net.minecraft.util.Identifier; - -class UParticles extends com.minelittlepony.unicopia.UParticles { - static void bootstrap() { - ParticleFactoryRegistry.instance().register(UNICORN_MAGIC, ParticleUnicornMagic::new); - ParticleFactoryRegistry.instance().register(CHANGELING_MAGIC, ParticleChangelingMagic::new); - ParticleFactoryRegistry.instance().register(RAIN_DROPS, ParticleRaindrops::new); - ParticleFactoryRegistry.instance().register(SPHERE, ParticleSphere::new); - ParticleFactoryRegistry.instance().register(DISK, ParticleDisk::new); - } -} diff --git a/src/main/java/com/minelittlepony/unicopia/client/UEntityRenderers.java b/src/main/java/com/minelittlepony/unicopia/client/URenderers.java similarity index 60% rename from src/main/java/com/minelittlepony/unicopia/client/UEntityRenderers.java rename to src/main/java/com/minelittlepony/unicopia/client/URenderers.java index bbcd56ef..d7f10468 100644 --- a/src/main/java/com/minelittlepony/unicopia/client/UEntityRenderers.java +++ b/src/main/java/com/minelittlepony/unicopia/client/URenderers.java @@ -1,5 +1,11 @@ package com.minelittlepony.unicopia.client; +import com.minelittlepony.unicopia.UParticles; +import com.minelittlepony.unicopia.client.particle.ParticleChangelingMagic; +import com.minelittlepony.unicopia.client.particle.ParticleDisk; +import com.minelittlepony.unicopia.client.particle.ParticleRaindrops; +import com.minelittlepony.unicopia.client.particle.ParticleSphere; +import com.minelittlepony.unicopia.client.particle.ParticleUnicornMagic; import com.minelittlepony.unicopia.client.render.entity.ButterflyEntityRenderer; import com.minelittlepony.unicopia.client.render.entity.RenderCloud; import com.minelittlepony.unicopia.client.render.entity.RenderCuccoon; @@ -7,11 +13,11 @@ import com.minelittlepony.unicopia.client.render.entity.RenderRainbow; import com.minelittlepony.unicopia.client.render.entity.RenderSpear; import com.minelittlepony.unicopia.client.render.entity.RenderSpellbook; import com.minelittlepony.unicopia.client.render.entity.SpellcastEntityRenderer; -import com.minelittlepony.unicopia.entity.AdvancedProjectileEntity; +import com.minelittlepony.unicopia.entity.ProjectileEntity; import com.minelittlepony.unicopia.entity.ButterflyEntity; import com.minelittlepony.unicopia.entity.CloudEntity; -import com.minelittlepony.unicopia.entity.EntityCuccoon; -import com.minelittlepony.unicopia.entity.EntitySpear; +import com.minelittlepony.unicopia.entity.CuccoonEntity; +import com.minelittlepony.unicopia.entity.SpearEntity; import com.minelittlepony.unicopia.entity.RainbowEntity; import com.minelittlepony.unicopia.entity.SpellbookEntity; import com.minelittlepony.unicopia.entity.SpellcastEntity; @@ -31,15 +37,21 @@ import net.minecraft.world.biome.OceanBiome; import net.minecraft.world.biome.PlainsBiome; import net.minecraft.world.biome.RiverBiome; -public class UEntityRenderers { +public class URenderers { static void bootstrap() { EntityRendererRegistry.INSTANCE.register(CloudEntity.class, RenderCloud::new); EntityRendererRegistry.INSTANCE.register(SpellcastEntity.class, SpellcastEntityRenderer::new); - EntityRendererRegistry.INSTANCE.register(AdvancedProjectileEntity.class, (manager, context) -> new FlyingItemEntityRenderer<>(manager, MinecraftClient.getInstance().getItemRenderer())); + EntityRendererRegistry.INSTANCE.register(ProjectileEntity.class, (manager, context) -> new FlyingItemEntityRenderer<>(manager, MinecraftClient.getInstance().getItemRenderer())); EntityRendererRegistry.INSTANCE.register(SpellbookEntity.class, RenderSpellbook::new); EntityRendererRegistry.INSTANCE.register(RainbowEntity.class, RenderRainbow::new); EntityRendererRegistry.INSTANCE.register(ButterflyEntity.class, ButterflyEntityRenderer::new); - EntityRendererRegistry.INSTANCE.register(EntityCuccoon.class, RenderCuccoon::new); - EntityRendererRegistry.INSTANCE.register(EntitySpear.class, RenderSpear::new); + EntityRendererRegistry.INSTANCE.register(CuccoonEntity.class, RenderCuccoon::new); + EntityRendererRegistry.INSTANCE.register(SpearEntity.class, RenderSpear::new); + + ParticleFactoryRegistry.instance().register(UParticles.UNICORN_MAGIC, ParticleUnicornMagic::new); + ParticleFactoryRegistry.instance().register(UParticles.CHANGELING_MAGIC, ParticleChangelingMagic::new); + ParticleFactoryRegistry.instance().register(UParticles.RAIN_DROPS, ParticleRaindrops::new); + ParticleFactoryRegistry.instance().register(UParticles.SPHERE, ParticleSphere::new); + ParticleFactoryRegistry.instance().register(UParticles.DISK, ParticleDisk::new); } } diff --git a/src/main/java/com/minelittlepony/unicopia/client/input/InversionAwareKeyboardInput.java b/src/main/java/com/minelittlepony/unicopia/client/input/InversionAwareKeyboardInput.java index e7ea3c0f..393544d6 100644 --- a/src/main/java/com/minelittlepony/unicopia/client/input/InversionAwareKeyboardInput.java +++ b/src/main/java/com/minelittlepony/unicopia/client/input/InversionAwareKeyboardInput.java @@ -1,6 +1,6 @@ package com.minelittlepony.unicopia.client.input; -import com.minelittlepony.unicopia.UClient; +import com.minelittlepony.unicopia.InteractionManager; import com.minelittlepony.unicopia.entity.capabilities.IPlayer; import net.minecraft.client.MinecraftClient; @@ -40,7 +40,7 @@ public class InversionAwareKeyboardInput extends KeyboardInput { this.movementSideways = proxy.movementSideways; this.movementForward = proxy.movementForward; - IPlayer player = UClient.instance().getIPlayer(); + IPlayer player = InteractionManager.instance().getIPlayer(); if (player.getGravity().getGravitationConstant() < 0) { boolean tmp = pressingLeft; diff --git a/src/main/java/com/minelittlepony/unicopia/client/input/Keyboard.java b/src/main/java/com/minelittlepony/unicopia/client/input/Keyboard.java index f0b89141..3a13d43f 100644 --- a/src/main/java/com/minelittlepony/unicopia/client/input/Keyboard.java +++ b/src/main/java/com/minelittlepony/unicopia/client/input/Keyboard.java @@ -1,6 +1,6 @@ package com.minelittlepony.unicopia.client.input; -import com.minelittlepony.unicopia.UClient; +import com.minelittlepony.unicopia.ServerInteractionManager; public final class Keyboard { private static IKeyBindingHandler keyHandler; @@ -8,7 +8,7 @@ public final class Keyboard { public static IKeyBindingHandler getKeyHandler() { if (keyHandler == null) { - if (UClient.isClientSide()) { + if (ServerInteractionManager.isClientSide()) { keyHandler = new KeyBindingsHandler(); } else { keyHandler = bind -> {}; diff --git a/src/main/java/com/minelittlepony/unicopia/client/input/MouseControl.java b/src/main/java/com/minelittlepony/unicopia/client/input/MouseControl.java index d44e0c9d..8b0c9052 100644 --- a/src/main/java/com/minelittlepony/unicopia/client/input/MouseControl.java +++ b/src/main/java/com/minelittlepony/unicopia/client/input/MouseControl.java @@ -1,6 +1,6 @@ package com.minelittlepony.unicopia.client.input; -import com.minelittlepony.unicopia.UClient; +import com.minelittlepony.unicopia.InteractionManager; import net.minecraft.client.MinecraftClient; import net.minecraft.client.Mouse; @@ -13,7 +13,7 @@ public class MouseControl extends Mouse { @Override public void updateMouse() { - if (UClient.instance().getIPlayer().getGravity().getGravitationConstant() < 0) { + if (InteractionManager.instance().getIPlayer().getGravity().getGravitationConstant() < 0) { //cursorDeltaX = -cursorDeltaX; //cursorDeltaY = -cursorDeltaY; } diff --git a/src/main/java/com/minelittlepony/unicopia/client/particle/ParticleChangelingMagic.java b/src/main/java/com/minelittlepony/unicopia/client/particle/ParticleChangelingMagic.java index 3b3c3321..8d7e2d89 100644 --- a/src/main/java/com/minelittlepony/unicopia/client/particle/ParticleChangelingMagic.java +++ b/src/main/java/com/minelittlepony/unicopia/client/particle/ParticleChangelingMagic.java @@ -12,7 +12,7 @@ public class ParticleChangelingMagic extends PortalParticle { private int baseTextureIndex = 128; - public ParticleChangelingMagic(ParticleEffect type, World world, double x, double y, double z, double dx, double dy, double dz) { + public ParticleChangelingMagic(World world, double x, double y, double z, double dx, double dy, double dz) { super(world, x, y, z, dx, dy, dz); float intensity = rand.nextFloat() * 0.6F + 0.4F; diff --git a/src/main/java/com/minelittlepony/unicopia/client/render/entity/RenderCuccoon.java b/src/main/java/com/minelittlepony/unicopia/client/render/entity/RenderCuccoon.java index 9d7d1f70..5da3be60 100644 --- a/src/main/java/com/minelittlepony/unicopia/client/render/entity/RenderCuccoon.java +++ b/src/main/java/com/minelittlepony/unicopia/client/render/entity/RenderCuccoon.java @@ -1,9 +1,9 @@ package com.minelittlepony.unicopia.client.render.entity; -import com.minelittlepony.unicopia.UClient; +import com.minelittlepony.unicopia.InteractionManager; import com.minelittlepony.unicopia.Unicopia; import com.minelittlepony.unicopia.client.render.entity.model.ModelCuccoon; -import com.minelittlepony.unicopia.entity.EntityCuccoon; +import com.minelittlepony.unicopia.entity.CuccoonEntity; import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.GlStateManager; @@ -12,7 +12,7 @@ import net.minecraft.client.renderer.entity.RenderManager; import net.minecraft.entity.Entity; import net.minecraft.util.Identifier; -public class RenderCuccoon extends RenderLivingBase { +public class RenderCuccoon extends RenderLivingBase { private static final Identifier TEXTURE = new Identifier(Unicopia.MODID, "textures/entity/cuccoon.png"); @@ -21,22 +21,22 @@ public class RenderCuccoon extends RenderLivingBase { } @Override - protected Identifier getEntityTexture(EntityCuccoon entity) { + protected Identifier getEntityTexture(CuccoonEntity entity) { return TEXTURE; } @Override - protected float getDeathMaxRotation(EntityCuccoon entity) { + protected float getDeathMaxRotation(CuccoonEntity entity) { return 0; } @Override - public void doRender(EntityCuccoon entity, double x, double y, double z, float entityYaw, float partialTicks) { + public void doRender(CuccoonEntity entity, double x, double y, double z, float entityYaw, float partialTicks) { if (entity.isBeingRidden()) { Entity rider = entity.getPassengers().get(0); - if (!(rider == MinecraftClient.instance().player) || UClient.instance().getViewMode() != 0) { + if (!(rider == MinecraftClient.instance().player) || InteractionManager.instance().getViewMode() != 0) { GlStateManager.enableAlpha(); GlStateManager.enableBlend(); diff --git a/src/main/java/com/minelittlepony/unicopia/client/render/entity/RenderSpear.java b/src/main/java/com/minelittlepony/unicopia/client/render/entity/RenderSpear.java index 6f8f098b..44dd4c25 100644 --- a/src/main/java/com/minelittlepony/unicopia/client/render/entity/RenderSpear.java +++ b/src/main/java/com/minelittlepony/unicopia/client/render/entity/RenderSpear.java @@ -1,13 +1,13 @@ package com.minelittlepony.unicopia.client.render.entity; import com.minelittlepony.unicopia.Unicopia; -import com.minelittlepony.unicopia.entity.EntitySpear; +import com.minelittlepony.unicopia.entity.SpearEntity; import net.minecraft.client.renderer.entity.RenderArrow; import net.minecraft.client.renderer.entity.RenderManager; import net.minecraft.util.Identifier; -public class RenderSpear extends RenderArrow { +public class RenderSpear extends RenderArrow { public static final Identifier TEXTURE = new Identifier(Unicopia.MODID, "textures/entity/projectiles/spear.png"); public RenderSpear(RenderManager manager) { @@ -15,7 +15,7 @@ public class RenderSpear extends RenderArrow { } @Override - protected Identifier getEntityTexture(EntitySpear entity) { + protected Identifier getEntityTexture(SpearEntity entity) { return TEXTURE; } } diff --git a/src/main/java/com/minelittlepony/unicopia/client/render/entity/model/ModelCuccoon.java b/src/main/java/com/minelittlepony/unicopia/client/render/entity/model/ModelCuccoon.java index 0f3ad5ee..95d37e51 100644 --- a/src/main/java/com/minelittlepony/unicopia/client/render/entity/model/ModelCuccoon.java +++ b/src/main/java/com/minelittlepony/unicopia/client/render/entity/model/ModelCuccoon.java @@ -1,6 +1,6 @@ package com.minelittlepony.unicopia.client.render.entity.model; -import com.minelittlepony.unicopia.entity.EntityCuccoon; +import com.minelittlepony.unicopia.entity.CuccoonEntity; import net.minecraft.client.model.ModelBase; import net.minecraft.client.model.ModelRenderer; @@ -40,7 +40,7 @@ public class ModelCuccoon extends ModelBase { @Override public void render(Entity entity, float limbSwing, float limbSwingAmount, float ageInTicks, float netHeadYaw, float headPitch, float scale) { - float breatheAmount = ((EntityCuccoon)entity).getBreatheAmount(ageInTicks) / 8; + float breatheAmount = ((CuccoonEntity)entity).getBreatheAmount(ageInTicks) / 8; GlStateManager.pushMatrix(); diff --git a/src/main/java/com/minelittlepony/unicopia/command/CommandDisguise.java b/src/main/java/com/minelittlepony/unicopia/command/CommandDisguise.java deleted file mode 100644 index afddb040..00000000 --- a/src/main/java/com/minelittlepony/unicopia/command/CommandDisguise.java +++ /dev/null @@ -1,103 +0,0 @@ -package com.minelittlepony.unicopia.command; - -import java.util.List; - -import com.minelittlepony.unicopia.SpeciesList; -import com.minelittlepony.unicopia.entity.capabilities.IPlayer; -import com.minelittlepony.unicopia.magic.spells.SpellDisguise; - -import net.minecraft.command.CommandException; -import net.minecraft.entity.Entity; -import net.minecraft.server.MinecraftServer; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.World; - -class CommandDisguise extends Command { - - @Override - public String getName() { - return "disguise"; - } - - @Override - public int getRequiredPermissionLevel() { - return 2; - } - - @Override - public String getUsage(ICommandSender sender) { - return "commands.disguise.usage"; - } - - @Override - public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException { - if (args.length < 2) { - throw new WrongUsageException(getUsage(sender)); - } - - ServerPlayerEntity player = args.length > 1 ? getPlayer(server, sender, args[0]) : getCommandSenderAsPlayer(sender); - - IPlayer iplayer = SpeciesList.instance().getPlayer(player); - - Entity entity = constructDisguiseEntity(player.world, args); - - if (entity == null) { - throw new CommandException("commands.disguise.notfound", args[1]); - } - - SpellDisguise effect = iplayer.getEffect(SpellDisguise.class, true); - - if (effect == null) { - iplayer.setEffect(new SpellDisguise().setDisguise(entity)); - } else { - effect.setDisguise(entity); - } - - if (player != sender) { - notifyCommandListener(sender, this, 1, "commands.disguise.success.other", player.getName(), entity.getName()); - } else { - if (player.getEntityWorld().getGameRules().getBoolean("sendCommandFeedback")) { - player.sendMessage(new TextComponentTranslation("commands.disguise.success.self", entity.getName())); - } - notifyCommandListener(sender, this, 1, "commands.disguise.success.otherself", player.getName(), entity.getName()); - } - } - - protected Entity constructDisguiseEntity(World world, String[] args) throws CommandException { - CompoundTag nbt = getEntityNBT(args); - nbt.setString("id", args[1]); - - return AnvilChunkLoader.readWorldEntityPos(nbt, world, 0, 0, 0, false); - } - - protected CompoundTag getEntityNBT(String[] args) throws CommandException { - if (args.length > 2) { - try { - return JsonToNBT.getTagFromJson(buildString(args, 2)); - } catch (NBTException e) { - throw new CommandException("commands.summon.tagError", e.getMessage()); - } - } - - return new CompoundTag(); - } - - @Override - public List getTabCompletions(MinecraftServer server, ICommandSender sender, String[] args, BlockPos pos) { - - if (args.length == 1) { - return getListOfStringsMatchingLastWord(args, server.getOnlinePlayerNames()); - } - - if (args.length == 2) { - return getListOfStringsMatchingLastWord(args, EntityList.getEntityNameList()); - } - - return null; - } - - @Override - public boolean isUsernameIndex(String[] args, int index) { - return index == 1; - } -} diff --git a/src/main/java/com/minelittlepony/unicopia/command/CommandGravity.java b/src/main/java/com/minelittlepony/unicopia/command/CommandGravity.java deleted file mode 100644 index 91381259..00000000 --- a/src/main/java/com/minelittlepony/unicopia/command/CommandGravity.java +++ /dev/null @@ -1,84 +0,0 @@ -package com.minelittlepony.unicopia.command; - -import java.util.List; - -import com.minelittlepony.unicopia.SpeciesList; -import com.minelittlepony.unicopia.entity.capabilities.IPlayer; - -import net.minecraft.command.CommandBase; -import net.minecraft.command.CommandException; -import net.minecraft.command.ICommandSender; -import net.minecraft.command.WrongUsageException; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.server.MinecraftServer; -import net.minecraft.util.math.BlockPos; -import net.minecraft.util.text.TextComponentTranslation; - -class CommandGravity extends CommandBase { - - public String getName() { - return "gravity"; - } - - public int getRequiredPermissionLevel() { - return 4; - } - - public String getUsage(ICommandSender sender) { - return "commands.gravity.usage"; - } - - public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException { - if (args.length < 2) { - throw new WrongUsageException(getUsage(sender)); - } - - PlayerEntity player = getCommandSenderAsPlayer(sender); - IPlayer iplayer = SpeciesList.instance().getPlayer(player); - - - - if (args[0].contentEquals("get")) { - String translationKey = "commands.gravity.get"; - - float gravity = iplayer.getGravity().getGravitationConstant(); - - if (sender == player) { - player.sendMessage(new TextComponentTranslation(translationKey, gravity)); - } - - notifyCommandListener(sender, this, 1, translationKey + ".other", player.getName(), gravity); - - } else if (args[0].contentEquals("set") || args.length > 2) { - String translationKey = "commands.gravity.set"; - - float gravity = Float.valueOf(args[2]); - - iplayer.getGravity().setGraviationConstant(gravity); - iplayer.sendCapabilities(true); - - if (sender == player) { - player.sendMessage(new TextComponentTranslation(translationKey, gravity)); - } - - notifyCommandListener(sender, this, 1, translationKey + ".other", player.getName(), gravity); - } else { - throw new WrongUsageException(getUsage(sender)); - } - } - - /** - * Adds the strings available in this command to the given list of tab completion options. - */ - public List getTabCompletions(MinecraftServer server, ICommandSender sender, String[] args, BlockPos pos) { - if (args.length == 1) { - return getListOfStringsMatchingLastWord(args, "get", "set"); - } - - if (args.length == 2) { - return getListOfStringsMatchingLastWord(args, server.getOnlinePlayerNames()); - } - - return null; - } -} diff --git a/src/main/java/com/minelittlepony/unicopia/command/CommandOverrideGameMode.java b/src/main/java/com/minelittlepony/unicopia/command/CommandOverrideGameMode.java deleted file mode 100644 index 69451be3..00000000 --- a/src/main/java/com/minelittlepony/unicopia/command/CommandOverrideGameMode.java +++ /dev/null @@ -1,51 +0,0 @@ -package com.minelittlepony.unicopia.command; - -import com.minelittlepony.unicopia.SpeciesList; -import com.minelittlepony.unicopia.entity.capabilities.IPlayer; - -import net.minecraft.command.CommandException; -import net.minecraft.command.CommandGameMode; -import net.minecraft.command.ICommandSender; -import net.minecraft.command.WrongUsageException; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.server.MinecraftServer; -import net.minecraft.util.text.ITextComponent; -import net.minecraft.util.text.TextComponentTranslation; -import net.minecraft.world.GameType; - -class CommandOverrideGameMode extends CommandGameMode { - - @Override - public void execute(MinecraftServer server, ICommandSender sender, String[] params) throws CommandException { - - if (params.length <= 0) { - throw new WrongUsageException("commands.gamemode.usage"); - } - - GameType gametype = getGameModeFromCommand(sender, params[0]); - - PlayerEntity player = params.length >= 2 ? getPlayer(server, sender, params[1]) : getCommandSenderAsPlayer(sender); - - updateGameMode(player, gametype); - - ITextComponent mode = new TextComponentTranslation("gameMode." + gametype.getName(), new Object[0]); - - if (sender.getEntityWorld().getGameRules().getBoolean("sendCommandFeedback")) { - player.sendMessage(new TextComponentTranslation("gameMode.changed", mode)); - } - - if (player == sender) { - notifyCommandListener(sender, this, 1, "commands.gamemode.success.self", mode); - } else { - notifyCommandListener(sender, this, 1, "commands.gamemode.success.other", player.getName(), mode); - } - } - - protected void updateGameMode(PlayerEntity player, GameType m) { - player.setGameType(m); - - IPlayer iplayer = SpeciesList.instance().getPlayer(player); - - iplayer.setSpecies(iplayer.getSpecies()); - } -} diff --git a/src/main/java/com/minelittlepony/unicopia/command/CommandRacelist.java b/src/main/java/com/minelittlepony/unicopia/command/CommandRacelist.java deleted file mode 100644 index 6e439d0c..00000000 --- a/src/main/java/com/minelittlepony/unicopia/command/CommandRacelist.java +++ /dev/null @@ -1,100 +0,0 @@ -package com.minelittlepony.unicopia.command; - -import java.util.ArrayList; -import java.util.List; - -import com.minelittlepony.unicopia.Race; -import com.minelittlepony.unicopia.SpeciesList; - -import net.minecraft.command.CommandBase; -import net.minecraft.command.CommandException; -import net.minecraft.command.ICommandSender; -import net.minecraft.command.WrongUsageException; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.server.MinecraftServer; -import net.minecraft.util.math.BlockPos; -import net.minecraft.util.text.ITextComponent; -import net.minecraft.util.text.TextComponentTranslation; -import net.minecraft.util.text.TextFormatting; - -class CommandRacelist extends CommandBase { - - public String getName() { - return "racelist"; - } - - public int getRequiredPermissionLevel() { - return 4; - } - - public String getUsage(ICommandSender sender) { - return "commands.racelist.usage"; - } - - public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException { - if (args.length < 2) { - throw new WrongUsageException(getUsage(sender)); - } - - PlayerEntity player = getCommandSenderAsPlayer(sender); - - Race race = Race.fromName(args[1], Race.EARTH); - - TextComponentTranslation formattedName = new TextComponentTranslation(race.name().toLowerCase()); - formattedName.getStyle().setColor(TextFormatting.GOLD); - - if (race.isDefault()) { - player.sendMessage(new TextComponentTranslation("commands.racelist.illegal", formattedName)); - } else if (args[0].contentEquals("allow")) { - String translationKey = "commands.racelist.allowed"; - - if (!SpeciesList.instance().whiteListRace(race)) { - translationKey += ".failed"; - } - - if (sender == player) { - ITextComponent comp = new TextComponentTranslation(translationKey, formattedName); - comp.getStyle().setColor(TextFormatting.GREEN); - player.sendMessage(comp); - } - notifyCommandListener(sender, this, 1, translationKey + ".other", player.getName(), formattedName); - - } else if (args[0].contentEquals("disallow")) { - String translationKey = "commands.racelist.disallowed"; - - if (!SpeciesList.instance().unwhiteListRace(race)) { - translationKey += ".failed"; - } - - if (sender == player) { - ITextComponent comp = new TextComponentTranslation(translationKey, formattedName); - comp.getStyle().setColor(TextFormatting.GREEN); - player.sendMessage(comp); - } - notifyCommandListener(sender, this, 1, translationKey + ".other", player.getName(), formattedName); - } else { - throw new WrongUsageException(getUsage(sender)); - } - } - - /** - * Adds the strings available in this command to the given list of tab completion options. - */ - public List getTabCompletions(MinecraftServer server, ICommandSender sender, String[] args, BlockPos pos) { - if (args.length == 1) { - return getListOfStringsMatchingLastWord(args, "allow", "disallow"); - } - - if (args.length == 2) { - ArrayList names = new ArrayList(); - - for (Race i : Race.values()) { - names.add(i.name().toLowerCase()); - } - - return getListOfStringsMatchingLastWord(args, names.stream().toArray(String[]::new)); - } - - return null; - } -} diff --git a/src/main/java/com/minelittlepony/unicopia/command/CommandSpecies.java b/src/main/java/com/minelittlepony/unicopia/command/CommandSpecies.java deleted file mode 100644 index 3458e15b..00000000 --- a/src/main/java/com/minelittlepony/unicopia/command/CommandSpecies.java +++ /dev/null @@ -1,213 +0,0 @@ -package com.minelittlepony.unicopia.command; - -import java.util.ArrayList; -import java.util.List; - -import com.minelittlepony.unicopia.Race; -import com.minelittlepony.unicopia.SpeciesList; - -import net.minecraft.command.CommandBase; -import net.minecraft.command.CommandException; -import net.minecraft.command.ICommandSender; -import net.minecraft.command.WrongUsageException; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.entity.player.ServerPlayerEntity; -import net.minecraft.server.MinecraftServer; -import net.minecraft.util.math.BlockPos; -import net.minecraft.util.text.ITextComponent; -import net.minecraft.util.text.TextComponentString; -import net.minecraft.util.text.TextComponentTranslation; -import net.minecraft.util.text.TextFormatting; - -class CommandSpecies extends CommandBase { - - @Override - public String getName() { - return "race"; - } - - @Override - public int getRequiredPermissionLevel() { - return 0; - } - - @Override - public boolean checkPermission(MinecraftServer server, ICommandSender sender) { - return sender.canUseCommand(getRequiredPermissionLevel(), "help"); - } - - @Override - public String getUsage(ICommandSender sender) { - return "commands.race.usage"; - } - - @Override - public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException { - if (!processCommand(server, sender, args)) { - throw new WrongUsageException(getUsage(sender)); - } - } - - protected boolean processCommand(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException { - - if (args.length < 1) { - return false; - } - - int playerIndex = this.getPlayerIndex(args); - - ServerPlayerEntity player = args.length > playerIndex ? getPlayer(server, sender, args[playerIndex]) : getCommandSenderAsPlayer(sender); - - if (args.length >= 2) { - switch (args[0]) { - case "set": return updateSpecies(sender, player, args); - case "describe": return describeSpecies(player, args); - } - } - - switch (args[0]) { - case "get": return printSpecies(sender, player); - case "list": return list(player); - } - - return false; - } - - protected int getPlayerIndex(String[] args) { - switch (args[0]) { - case "set": - case "describe": return 2; - default: return 1; - } - } - - protected boolean updateSpecies(ICommandSender sender, PlayerEntity player, String[] args) { - Race species = Race.fromName(args[1], Race.HUMAN); - - if (species.isDefault()) { - if (player.getEntityWorld().getGameRules().getBoolean("sendCommandFeedback")) { - ITextComponent message = new TextComponentTranslation("commands.race.fail", args[1].toUpperCase()); - message.getStyle().setColor(TextFormatting.RED); - - player.sendMessage(message); - } - } else if (SpeciesList.instance().speciesPermitted(species, player)) { - SpeciesList.instance().getPlayer(player).setSpecies(species); - - ITextComponent formattedName = new TextComponentTranslation(species.name().toLowerCase()); - - if (player != sender) { - notifyCommandListener(sender, this, 1, "commands.race.success.other", player.getName(), formattedName); - } else { - if (player.getEntityWorld().getGameRules().getBoolean("sendCommandFeedback")) { - player.sendMessage(new TextComponentTranslation("commands.race.success.self")); - } - notifyCommandListener(sender, this, 1, "commands.race.success.otherself", player.getName(), formattedName); - } - } else if (player.getEntityWorld().getGameRules().getBoolean("sendCommandFeedback")) { - player.sendMessage(new TextComponentTranslation("commands.race.permission")); - } - - return true; - } - - protected boolean printSpecies(ICommandSender sender, PlayerEntity player) { - Race spec = SpeciesList.instance().getPlayer(player).getSpecies(); - - String name = "commands.race.tell."; - name += player == sender ? "self" : "other"; - - ITextComponent race = new TextComponentTranslation(spec.getTranslationKey()); - ITextComponent message = new TextComponentTranslation(name); - - race.getStyle().setColor(TextFormatting.GOLD); - - message.appendSibling(race); - - player.sendMessage(message); - - return true; - } - - protected boolean list(PlayerEntity player) { - player.sendMessage(new TextComponentTranslation("commands.race.list")); - - ITextComponent message = new TextComponentString(""); - - boolean first = true; - for (Race i : Race.values()) { - if (!i.isDefault() && SpeciesList.instance().speciesPermitted(i, player)) { - message.appendSibling(new TextComponentString((!first ? "\n" : "") + " - " + i.name().toLowerCase())); - first = false; - } - } - - message.getStyle().setColor(TextFormatting.GOLD); - - player.sendMessage(message); - - return true; - } - - protected boolean describeSpecies(PlayerEntity player, String[] args) { - Race species = Race.fromName(args[1], null); - - if (species == null) { - if (player.getEntityWorld().getGameRules().getBoolean("sendCommandFeedback")) { - player.sendMessage(new TextComponentTranslation("commands.race.fail", args[1].toUpperCase())); - } - } else { - String name = species.name().toLowerCase(); - - ITextComponent line1 = new TextComponentTranslation(String.format("commands.race.describe.%s.1", name)); - line1.getStyle().setColor(TextFormatting.YELLOW); - - player.sendMessage(line1); - - player.sendMessage(new TextComponentTranslation(String.format("commands.race.describe.%s.2", name))); - - ITextComponent line3 = new TextComponentTranslation(String.format("commands.race.describe.%s.3", name)); - line3.getStyle().setColor(TextFormatting.RED); - - player.sendMessage(line3); - } - - return true; - } - - /** - * Adds the strings available in this command to the given list of tab completion options. - */ - @Override - public List getTabCompletions(MinecraftServer server, ICommandSender sender, String[] args, BlockPos pos) { - - if (args.length == 1) { - return getListOfStringsMatchingLastWord(args, "get", "set", "list", "describe"); - } - - if (args.length == 2 && (args[0].contentEquals("set") || args[0].contentEquals("describe"))) { - ArrayList names = new ArrayList(); - - PlayerEntity player = sender instanceof PlayerEntity ? (PlayerEntity)sender : null; - - for (Race i : Race.values()) { - if (args[0].contentEquals("describe") || (!i.isDefault() && SpeciesList.instance().speciesPermitted(i, player))) { - names.add(i.name().toLowerCase()); - } - } - - return getListOfStringsMatchingLastWord(args, names.stream().toArray(String[]::new)); - } - - if ((args.length == 3 && args[0].contentEquals("set")) || (args[0].contentEquals("get") && args.length == 2)) { - return getListOfStringsMatchingLastWord(args, server.getOnlinePlayerNames()); - } - - return null; - } - - @Override - public boolean isUsernameIndex(String[] args, int index) { - return index == getPlayerIndex(args); - } -} diff --git a/src/main/java/com/minelittlepony/unicopia/command/Commands.java b/src/main/java/com/minelittlepony/unicopia/command/Commands.java index 71874cf6..926befd0 100644 --- a/src/main/java/com/minelittlepony/unicopia/command/Commands.java +++ b/src/main/java/com/minelittlepony/unicopia/command/Commands.java @@ -1,13 +1,15 @@ package com.minelittlepony.unicopia.command; +import net.fabricmc.fabric.api.registry.CommandRegistry; + public class Commands { public static void bootstrap() { - event.registerServerCommand(new CommandOverrideGameMode()); - event.registerServerCommand(new CommandSpecies()); - event.registerServerCommand(new CommandRacelist()); - event.registerServerCommand(new CommandDisguise()); - event.registerServerCommand(new CommandGravity()); + CommandRegistry.INSTANCE.register(false, SpeciesCommand::register); + CommandRegistry.INSTANCE.register(false, RacelistCommand::register); + CommandRegistry.INSTANCE.register(false, DisguiseCommand::register); + CommandRegistry.INSTANCE.register(false, GravityCommand::register); - event.getServer().setAllowFlight(true); + // TODO: + //event.getServer().setAllowFlight(true); } } diff --git a/src/main/java/com/minelittlepony/unicopia/command/DisguiseCommand.java b/src/main/java/com/minelittlepony/unicopia/command/DisguiseCommand.java new file mode 100644 index 00000000..6f3ad753 --- /dev/null +++ b/src/main/java/com/minelittlepony/unicopia/command/DisguiseCommand.java @@ -0,0 +1,96 @@ +package com.minelittlepony.unicopia.command; + +import java.util.function.Function; + +import com.minelittlepony.unicopia.SpeciesList; +import com.minelittlepony.unicopia.entity.capabilities.IPlayer; +import com.minelittlepony.unicopia.magic.spells.SpellDisguise; +import com.mojang.brigadier.CommandDispatcher; +import com.mojang.brigadier.builder.LiteralArgumentBuilder; +import com.mojang.brigadier.exceptions.CommandSyntaxException; +import com.mojang.brigadier.exceptions.SimpleCommandExceptionType; + +import net.minecraft.command.arguments.EntitySummonArgumentType; +import net.minecraft.command.arguments.NbtCompoundTagArgumentType; +import net.minecraft.command.suggestion.SuggestionProviders; +import net.minecraft.entity.Entity; +import net.minecraft.entity.EntityType; +import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.nbt.CompoundTag; +import net.minecraft.server.command.CommandManager; +import net.minecraft.server.command.ServerCommandSource; +import net.minecraft.text.TranslatableText; +import net.minecraft.util.Identifier; +import net.minecraft.world.GameRules; + +class DisguiseCommand { + private static final SimpleCommandExceptionType FAILED_EXCEPTION = new SimpleCommandExceptionType(new TranslatableText("commands.disguise.notfound")); + + static void register(CommandDispatcher dispatcher) { + LiteralArgumentBuilder builder = CommandManager + .literal("disguise") + .requires(s -> s.hasPermissionLevel(2)) + .executes(context -> reveal(context.getSource(), context.getSource().getPlayer())); + + builder.then(CommandManager + .argument("entity", EntitySummonArgumentType.entitySummon()) + .suggests(SuggestionProviders.SUMMONABLE_ENTITIES) + .executes(context -> disguise(context.getSource(), + context.getSource().getPlayer(), + EntitySummonArgumentType.getEntitySummon(context, "entity"), + new CompoundTag(), true)) + .then(CommandManager.argument("nbt", NbtCompoundTagArgumentType.nbtCompound()) + .executes(context -> disguise(context.getSource(), + context.getSource().getPlayer(), + EntitySummonArgumentType.getEntitySummon(context, "entity"), + NbtCompoundTagArgumentType.getCompoundTag(context, "nbt"), false)) + )); + + dispatcher.register(builder); + } + + static int disguise(ServerCommandSource source, PlayerEntity player, Identifier id, CompoundTag nbt, boolean isSelf) throws CommandSyntaxException { + nbt = nbt.method_10553(); + nbt.putString("id", id.toString()); + + IPlayer iplayer = SpeciesList.instance().getPlayer(player); + + Entity entity = EntityType.loadEntityWithPassengers(nbt, source.getWorld(), Function.identity()); + + if (entity == null) { + throw FAILED_EXCEPTION.create(); + } + + SpellDisguise effect = iplayer.getEffect(SpellDisguise.class, true); + + if (effect == null) { + iplayer.setEffect(new SpellDisguise().setDisguise(entity)); + } else { + effect.setDisguise(entity); + } + + if (!isSelf) { + source.sendFeedback(new TranslatableText("commands.disguise.success.other", player.getName(), entity.getName()), true); + } else { + if (player.getEntityWorld().getGameRules().getBoolean(GameRules.SEND_COMMAND_FEEDBACK)) { + player.sendMessage(new TranslatableText("commands.disguise.success.self", entity.getName())); + } + source.sendFeedback(new TranslatableText("commands.disguise.success.otherself", player.getName(), entity.getName()), true); + } + + return 0; + } + + static int reveal(ServerCommandSource source, PlayerEntity player) { + IPlayer iplayer = SpeciesList.instance().getPlayer(player); + iplayer.getEffect(SpellDisguise.class).ifPresent(disguise -> { + disguise.setDead(); + }); + + if (player.getEntityWorld().getGameRules().getBoolean(GameRules.SEND_COMMAND_FEEDBACK)) { + player.sendMessage(new TranslatableText("commands.disguise.removed")); + } + + return 0; + } +} diff --git a/src/main/java/com/minelittlepony/unicopia/command/GravityCommand.java b/src/main/java/com/minelittlepony/unicopia/command/GravityCommand.java new file mode 100644 index 00000000..ce70359e --- /dev/null +++ b/src/main/java/com/minelittlepony/unicopia/command/GravityCommand.java @@ -0,0 +1,69 @@ +package com.minelittlepony.unicopia.command; + +import com.minelittlepony.unicopia.SpeciesList; +import com.minelittlepony.unicopia.entity.capabilities.IPlayer; +import com.mojang.brigadier.CommandDispatcher; +import com.mojang.brigadier.arguments.FloatArgumentType; +import com.mojang.brigadier.builder.LiteralArgumentBuilder; + +import net.minecraft.command.arguments.EntityArgumentType; +import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.server.command.CommandManager; +import net.minecraft.server.command.ServerCommandSource; +import net.minecraft.text.TranslatableText; + +class GravityCommand { + + static void register(CommandDispatcher dispatcher) { + LiteralArgumentBuilder builder = CommandManager.literal("gravity").requires(s -> s.hasPermissionLevel(4)); + + builder.then(CommandManager + .literal("get") + .executes(context -> get(context.getSource(), context.getSource().getPlayer(), true)) + ).then(CommandManager.argument("target", EntityArgumentType.player()) + .executes(context -> get(context.getSource(), EntityArgumentType.getPlayer(context, "target"), false)) + ); + builder.then(CommandManager + .literal("set") + .then(CommandManager.argument("gravity", FloatArgumentType.floatArg(-99, 99)) + .executes(context -> set(context.getSource(), context.getSource().getPlayer(), FloatArgumentType.getFloat(context, "gravity"), true)) + .then(CommandManager.argument("target", EntityArgumentType.player()) + .executes(context -> set(context.getSource(), EntityArgumentType.getPlayer(context, "target"), FloatArgumentType.getFloat(context, "gravity"), false)) + ))); + + dispatcher.register(builder); + } + + static int get(ServerCommandSource source, PlayerEntity player, boolean isSelf) { + String translationKey = "commands.gravity.get"; + + IPlayer iplayer = SpeciesList.instance().getPlayer(player); + + float gravity = iplayer.getGravity().getGravitationConstant(); + + if (isSelf) { + player.sendMessage(new TranslatableText(translationKey, gravity)); + } + + source.sendFeedback(new TranslatableText(translationKey + ".other", player.getName(), gravity), true); + + return 0; + } + + static int set(ServerCommandSource source, PlayerEntity player, float gravity, boolean isSelf) { + String translationKey = "commands.gravity.set"; + + IPlayer iplayer = SpeciesList.instance().getPlayer(player); + + iplayer.getGravity().setGraviationConstant(gravity); + iplayer.sendCapabilities(true); + + if (isSelf) { + player.sendMessage(new TranslatableText(translationKey, gravity)); + } + + source.sendFeedback(new TranslatableText(translationKey + ".other", player.getName(), gravity), true); + + return 0; + } +} diff --git a/src/main/java/com/minelittlepony/unicopia/command/RaceArgument.java b/src/main/java/com/minelittlepony/unicopia/command/RaceArgument.java new file mode 100644 index 00000000..9442ee41 --- /dev/null +++ b/src/main/java/com/minelittlepony/unicopia/command/RaceArgument.java @@ -0,0 +1,27 @@ +package com.minelittlepony.unicopia.command; + +import java.util.Arrays; +import java.util.Collection; +import java.util.stream.Collectors; + +import com.minelittlepony.unicopia.Race; +import com.mojang.brigadier.StringReader; +import com.mojang.brigadier.arguments.ArgumentType; +import com.mojang.brigadier.exceptions.CommandSyntaxException; + +class RaceArgument implements ArgumentType { + static final Collection EXAMPLES = Arrays.stream(Race.values()) + .filter(Race::isUsable) + .map(Race::name) + .collect(Collectors.toList()); + + @Override + public Race parse(StringReader reader) throws CommandSyntaxException { + return Race.fromName(reader.readUnquotedString(), Race.EARTH); + } + + @Override + public Collection getExamples() { + return EXAMPLES; + } +} \ No newline at end of file diff --git a/src/main/java/com/minelittlepony/unicopia/command/RacelistCommand.java b/src/main/java/com/minelittlepony/unicopia/command/RacelistCommand.java new file mode 100644 index 00000000..92d66efb --- /dev/null +++ b/src/main/java/com/minelittlepony/unicopia/command/RacelistCommand.java @@ -0,0 +1,53 @@ +package com.minelittlepony.unicopia.command; + +import java.util.function.BiFunction; + +import com.minelittlepony.unicopia.Race; +import com.minelittlepony.unicopia.SpeciesList; +import com.mojang.brigadier.CommandDispatcher; +import com.mojang.brigadier.builder.LiteralArgumentBuilder; + +import net.minecraft.server.command.CommandManager; +import net.minecraft.server.command.ServerCommandSource; +import net.minecraft.server.network.ServerPlayerEntity; +import net.minecraft.text.Text; +import net.minecraft.text.TranslatableText; +import net.minecraft.util.Formatting; + +class RacelistCommand { + + static void register(CommandDispatcher dispatcher) { + LiteralArgumentBuilder builder = CommandManager.literal("racelist").requires(s -> s.hasPermissionLevel(4)); + + builder.then(CommandManager.literal("allow") + .then(CommandManager.argument("race", new RaceArgument()) + .executes(context -> toggle(context.getSource(), context.getSource().getPlayer(), context.getArgument("race", Race.class), "allowed", SpeciesList::unwhiteListRace)) + )); + builder.then(CommandManager.literal("disallow") + .then(CommandManager.argument("race", new RaceArgument()) + .executes(context -> toggle(context.getSource(), context.getSource().getPlayer(), context.getArgument("race", Race.class), "disallowed", SpeciesList::whiteListRace)) + )); + + dispatcher.register(builder); + } + + static int toggle(ServerCommandSource source, ServerPlayerEntity player, Race race, String action, BiFunction func) { + String translationKey = "commands.racelist." + action; + + if (!func.apply(SpeciesList.instance(), race)) { + translationKey += ".failed"; + } + + Text formattedName = new TranslatableText(race.name().toLowerCase()); + formattedName.getStyle().setColor(Formatting.GOLD); + + Text comp = new TranslatableText(translationKey, formattedName); + comp.getStyle().setColor(Formatting.GREEN); + + player.sendMessage(comp); + + source.sendFeedback(new TranslatableText(translationKey + ".other", player.getName(), formattedName), true); + + return 0; + } +} diff --git a/src/main/java/com/minelittlepony/unicopia/command/SpeciesCommand.java b/src/main/java/com/minelittlepony/unicopia/command/SpeciesCommand.java new file mode 100644 index 00000000..68aefab9 --- /dev/null +++ b/src/main/java/com/minelittlepony/unicopia/command/SpeciesCommand.java @@ -0,0 +1,124 @@ +package com.minelittlepony.unicopia.command; + +import com.minelittlepony.unicopia.Race; +import com.minelittlepony.unicopia.SpeciesList; +import com.mojang.brigadier.CommandDispatcher; +import com.mojang.brigadier.builder.LiteralArgumentBuilder; + +import net.minecraft.command.arguments.EntityArgumentType; +import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.server.command.CommandManager; +import net.minecraft.server.command.ServerCommandSource; +import net.minecraft.text.LiteralText; +import net.minecraft.text.Text; +import net.minecraft.text.TranslatableText; +import net.minecraft.util.Formatting; +import net.minecraft.world.GameRules; + +class SpeciesCommand { + static void register(CommandDispatcher dispatcher) { + LiteralArgumentBuilder builder = CommandManager.literal("race"); + + builder.then(CommandManager.literal("get") + .executes(context -> get(context.getSource(), context.getSource().getPlayer(), true)) + .then(CommandManager.argument("target", EntityArgumentType.player()) + .executes(context -> get(context.getSource(), EntityArgumentType.getPlayer(context, "target"), false)) + )); + + builder.then(CommandManager.literal("set") + .then(CommandManager.argument("race", new RaceArgument()) + .executes(context -> set(context.getSource(), context.getSource().getPlayer(), context.getArgument("race", Race.class), true)) + .then(CommandManager.argument("target", EntityArgumentType.player()) + .executes(context -> set(context.getSource(), EntityArgumentType.getPlayer(context, "target"), context.getArgument("race", Race.class), false)) + ))); + + builder.then(CommandManager.literal("describe") + .then(CommandManager.argument("race", new RaceArgument()) + .executes(context -> describe(context.getSource().getPlayer(), context.getArgument("race", Race.class)) + ))); + + builder.then(CommandManager.literal("list") + .executes(context -> list(context.getSource().getPlayer()) + )); + + dispatcher.register(builder); + } + + static int set(ServerCommandSource source, PlayerEntity player, Race race, boolean isSelf) { + + if (SpeciesList.instance().speciesPermitted(race, player)) { + SpeciesList.instance().getPlayer(player).setSpecies(race); + + Text formattedName = new TranslatableText(race.name().toLowerCase()); + + if (!isSelf) { + source.sendFeedback(new TranslatableText("commands.race.success.other", player.getName(), formattedName), true); + } else { + if (player.getEntityWorld().getGameRules().getBoolean(GameRules.SEND_COMMAND_FEEDBACK)) { + player.sendMessage(new TranslatableText("commands.race.success.self")); + } + source.sendFeedback(new TranslatableText("commands.race.success.otherself", player.getName(), formattedName), true); + } + } else if (player.getEntityWorld().getGameRules().getBoolean(GameRules.SEND_COMMAND_FEEDBACK)) { + player.sendMessage(new TranslatableText("commands.race.permission")); + } + + return 0; + } + + static int get(ServerCommandSource source, PlayerEntity player, boolean isSelf) { + Race spec = SpeciesList.instance().getPlayer(player).getSpecies(); + + String name = "commands.race.tell."; + name += isSelf ? "self" : "other"; + + Text race = new TranslatableText(spec.getTranslationKey()); + Text message = new TranslatableText(name); + + race.getStyle().setColor(Formatting.GOLD); + + message.append(race); + + player.sendMessage(message); + + return 0; + } + + static int list(PlayerEntity player) { + player.sendMessage(new TranslatableText("commands.race.list")); + + Text message = new LiteralText(""); + + boolean first = true; + for (Race i : Race.values()) { + if (!i.isDefault() && SpeciesList.instance().speciesPermitted(i, player)) { + message.append(new TranslatableText((!first ? "\n" : "") + " - " + i.name().toLowerCase())); + first = false; + } + } + + message.getStyle().setColor(Formatting.GOLD); + + player.sendMessage(message); + + return 0; + } + + static int describe(PlayerEntity player, Race species) { + String name = species.name().toLowerCase(); + + Text line1 = new TranslatableText(String.format("commands.race.describe.%s.1", name)); + line1.getStyle().setColor(Formatting.YELLOW); + + player.sendMessage(line1); + + player.sendMessage(new TranslatableText(String.format("commands.race.describe.%s.2", name))); + + Text line3 = new TranslatableText(String.format("commands.race.describe.%s.3", name)); + line3.getStyle().setColor(Formatting.RED); + + player.sendMessage(line3); + + return 0; + } +} diff --git a/src/main/java/com/minelittlepony/unicopia/ducks/IItemEntity.java b/src/main/java/com/minelittlepony/unicopia/ducks/IItemEntity.java new file mode 100644 index 00000000..40d73172 --- /dev/null +++ b/src/main/java/com/minelittlepony/unicopia/ducks/IItemEntity.java @@ -0,0 +1,10 @@ +package com.minelittlepony.unicopia.ducks; + +import com.minelittlepony.unicopia.entity.capabilities.ItemEntityCapabilities; + +public interface IItemEntity extends IRaceContainerHolder { + + int getAge(); + + int getPickupDelay(); +} diff --git a/src/main/java/com/minelittlepony/unicopia/enchanting/SpellCraftingEvent.java b/src/main/java/com/minelittlepony/unicopia/enchanting/SpellCraftingEvent.java index c6e4dc1a..5c82fe01 100644 --- a/src/main/java/com/minelittlepony/unicopia/enchanting/SpellCraftingEvent.java +++ b/src/main/java/com/minelittlepony/unicopia/enchanting/SpellCraftingEvent.java @@ -6,8 +6,8 @@ import javax.annotation.Nullable; import com.google.gson.JsonObject; import com.google.gson.annotations.Expose; import com.minelittlepony.unicopia.item.MagicGemItem; -import com.minelittlepony.unicopia.spell.SpellAffinity; -import com.minelittlepony.unicopia.spell.SpellRegistry; +import com.minelittlepony.unicopia.magic.Affinity; +import com.minelittlepony.unicopia.magic.spells.SpellRegistry; import net.minecraft.item.ItemStack; @@ -30,7 +30,7 @@ public class SpellCraftingEvent { static class Condition implements IUnlockCondition { @Nonnull - SpellAffinity affinity; + Affinity affinity; @Expose String spell; @@ -39,7 +39,7 @@ public class SpellCraftingEvent { require(json, "affinity"); require(json, "spell"); - affinity = SpellAffinity.of(json.get("affinity").getAsString()); + affinity = Affinity.of(json.get("affinity").getAsString()); spell = json.get("spell").getAsString(); } diff --git a/src/main/java/com/minelittlepony/unicopia/enchanting/recipe/AffineIngredient.java b/src/main/java/com/minelittlepony/unicopia/enchanting/recipe/AffineIngredient.java new file mode 100644 index 00000000..0cc19193 --- /dev/null +++ b/src/main/java/com/minelittlepony/unicopia/enchanting/recipe/AffineIngredient.java @@ -0,0 +1,62 @@ +package com.minelittlepony.unicopia.enchanting.recipe; + +import java.util.stream.Stream; + +import javax.annotation.Nonnull; + +import com.google.gson.JsonElement; +import com.google.gson.JsonObject; +import net.minecraft.item.ItemStack; +import net.minecraft.util.Identifier; +import net.minecraft.util.PacketByteBuf; + +class AffineIngredient implements SpellIngredient { + + static final Serializer SERIALIZER = new Serializer() { + @Override + public AffineIngredient read(JsonElement json) { + return new AffineIngredient(new Identifier(json.getAsJsonObject().get("id").getAsString())); + } + + @Override + public AffineIngredient read(PacketByteBuf buff) { + return new AffineIngredient(new Identifier(buff.readString())); + } + + @Override + public void write(PacketByteBuf buff, AffineIngredient ingredient) { + buff.writeString(ingredient.res.toString()); + } + }; + + private final Identifier res; + + AffineIngredient(Identifier res) { + this.res = res; + } + + @Override + public ItemStack getStack() { + return AffineIngredients.instance().getIngredient(res).getStack(); + } + + @Override + public Stream getStacks() { + return AffineIngredients.instance().getIngredient(res).getStacks(); + } + + @Override + public boolean matches(ItemStack other, int materialMult) { + return AffineIngredients.instance().getIngredient(res).matches(other, materialMult); + } + + @Nonnull + static SpellIngredient parse(JsonObject json) { + return SERIALIZER.read(json); + } + + @Override + public Serializer getSerializer() { + return SERIALIZER; + } +} \ No newline at end of file diff --git a/src/main/java/com/minelittlepony/unicopia/enchanting/recipe/AffineIngredients.java b/src/main/java/com/minelittlepony/unicopia/enchanting/recipe/AffineIngredients.java index 66f55aea..4dab9790 100644 --- a/src/main/java/com/minelittlepony/unicopia/enchanting/recipe/AffineIngredients.java +++ b/src/main/java/com/minelittlepony/unicopia/enchanting/recipe/AffineIngredients.java @@ -1,9 +1,6 @@ package com.minelittlepony.unicopia.enchanting.recipe; import java.util.Map; -import java.util.stream.Stream; - -import javax.annotation.Nonnull; import com.google.common.collect.Maps; import com.google.gson.JsonObject; @@ -11,7 +8,6 @@ import com.google.gson.JsonParseException; import com.minelittlepony.unicopia.Unicopia; import com.minelittlepony.util.AssetWalker; -import net.minecraft.item.ItemStack; import net.minecraft.util.Identifier; public class AffineIngredients { @@ -50,33 +46,4 @@ public class AffineIngredients { storedIngredients.put(id, ingredient); } } - - static class AffineIngredient implements SpellIngredient { - - private final Identifier res; - - AffineIngredient(Identifier res) { - this.res = res; - } - - @Override - public ItemStack getStack() { - return instance().getIngredient(res).getStack(); - } - - @Override - public Stream getStacks() { - return instance().getIngredient(res).getStacks(); - } - - @Override - public boolean matches(ItemStack other, int materialMult) { - return instance().getIngredient(res).matches(other, materialMult); - } - - @Nonnull - static SpellIngredient parse(JsonObject json) { - return new AffineIngredient(new Identifier(json.get("id").getAsString())); - } - } } diff --git a/src/main/java/com/minelittlepony/unicopia/enchanting/recipe/SingleSpellIngredient.java b/src/main/java/com/minelittlepony/unicopia/enchanting/recipe/SingleSpellIngredient.java index 4ec0667e..746d0fec 100644 --- a/src/main/java/com/minelittlepony/unicopia/enchanting/recipe/SingleSpellIngredient.java +++ b/src/main/java/com/minelittlepony/unicopia/enchanting/recipe/SingleSpellIngredient.java @@ -3,14 +3,10 @@ package com.minelittlepony.unicopia.enchanting.recipe; import java.util.Optional; import java.util.stream.Stream; -import javax.annotation.Nullable; - import com.google.common.collect.Streams; import com.google.gson.JsonElement; import com.google.gson.JsonObject; import com.google.gson.JsonParseException; -import com.minelittlepony.unicopia.enchanting.recipe.AffineIngredients.AffineIngredient; -import com.minelittlepony.unicopia.enchanting.recipe.SpellIngredient.Serializer; import com.minelittlepony.unicopia.magic.spells.SpellRegistry; import net.minecraft.item.Item; @@ -68,7 +64,7 @@ class SingleSpellIngredient implements SpellIngredient { public Stream getStacks() { if (!contained.isEmpty()) { DefaultedList subItems = DefaultedList.of(); - contained.getItem().getSubItems(ItemGroup.SEARCH, subItems); + contained.getItem().appendStacks(ItemGroup.SEARCH, subItems); return subItems.stream(); } diff --git a/src/main/java/com/minelittlepony/unicopia/enchanting/recipe/SpellIngredient.java b/src/main/java/com/minelittlepony/unicopia/enchanting/recipe/SpellIngredient.java index b9fd3e97..cbd91cb6 100644 --- a/src/main/java/com/minelittlepony/unicopia/enchanting/recipe/SpellIngredient.java +++ b/src/main/java/com/minelittlepony/unicopia/enchanting/recipe/SpellIngredient.java @@ -1,5 +1,7 @@ package com.minelittlepony.unicopia.enchanting.recipe; +import java.util.HashMap; +import java.util.Map; import java.util.stream.Stream; import com.google.gson.JsonElement; @@ -8,10 +10,16 @@ import com.google.gson.JsonParseException; import net.minecraft.item.ItemStack; import net.minecraft.util.DefaultedList; import net.minecraft.util.PacketByteBuf; +import net.minecraft.util.SystemUtil; public interface SpellIngredient { SpellIngredient EMPTY = new SingleSpellIngredient(ItemStack.EMPTY, false); + Map> SERIALIZERS = SystemUtil.consume(new HashMap<>(), map -> { + map.put("compound", CompoundSpellIngredient.SERIALIZER); + map.put("single", SingleSpellIngredient.SERIALIZER); + map.put("affine", AffineIngredient.SERIALIZER); + }); Serializer SERIALIZER = new Serializer() { @Override @@ -25,12 +33,9 @@ public interface SpellIngredient { @Override public SpellIngredient read(PacketByteBuf buff) { - byte type = buff.readByte(); + String type = buff.readString(); - if (type == 0) { - return SingleSpellIngredient.SERIALIZER.read(buff); - } - return CompoundSpellIngredient.SERIALIZER.read(buff); + return SERIALIZERS.get(type).read(buff); } @Override diff --git a/src/main/java/com/minelittlepony/unicopia/entity/CloudEntity.java b/src/main/java/com/minelittlepony/unicopia/entity/CloudEntity.java index b90f7542..1a31e80e 100644 --- a/src/main/java/com/minelittlepony/unicopia/entity/CloudEntity.java +++ b/src/main/java/com/minelittlepony/unicopia/entity/CloudEntity.java @@ -155,24 +155,24 @@ public class CloudEntity extends FlyingEntity implements ICloudEntity, IInAnimat } @Override - protected void collideWithEntity(Entity other) { + protected void pushAway(Entity other) { if (other instanceof CloudEntity || other instanceof PlayerEntity) { if (other.y > y) { return; } - super.collideWithEntity(other); + super.pushAway(other); } } @Override - public void applyEntityCollision(Entity other) { + public void pushAwayFrom(Entity other) { if (other instanceof PlayerEntity) { if (EquinePredicates.INTERACT_WITH_CLOUDS.test((PlayerEntity)other)) { - super.applyEntityCollision(other); + super.pushAwayFrom(other); } } else if (other instanceof CloudEntity) { - super.applyEntityCollision(other); + super.pushAwayFrom(other); } } diff --git a/src/main/java/com/minelittlepony/unicopia/entity/EntityCuccoon.java b/src/main/java/com/minelittlepony/unicopia/entity/CuccoonEntity.java similarity index 90% rename from src/main/java/com/minelittlepony/unicopia/entity/EntityCuccoon.java rename to src/main/java/com/minelittlepony/unicopia/entity/CuccoonEntity.java index 4715c971..69c578c6 100644 --- a/src/main/java/com/minelittlepony/unicopia/entity/EntityCuccoon.java +++ b/src/main/java/com/minelittlepony/unicopia/entity/CuccoonEntity.java @@ -7,13 +7,11 @@ import javax.annotation.Nullable; import com.google.common.collect.Lists; import com.minelittlepony.unicopia.EquinePredicates; import com.minelittlepony.unicopia.Race; +import com.minelittlepony.unicopia.SpeciesList; import com.minelittlepony.unicopia.UParticles; import com.minelittlepony.unicopia.USounds; -import com.minelittlepony.unicopia.ability.IPower; -import com.minelittlepony.unicopia.particles.ParticleEmitter; import com.minelittlepony.util.MagicalDamageSource; -import net.minecraft.block.Block; import net.minecraft.block.Blocks; import net.minecraft.entity.Entity; import net.minecraft.entity.EntityDimensions; @@ -29,7 +27,6 @@ import net.minecraft.entity.effect.StatusEffectInstance; import net.minecraft.entity.effect.StatusEffects; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.item.ItemStack; -import net.minecraft.nbt.CompoundTag; import net.minecraft.particle.BlockStateParticleEffect; import net.minecraft.particle.ParticleTypes; import net.minecraft.sound.SoundEvent; @@ -43,18 +40,16 @@ import net.minecraft.util.math.Vec3d; import net.minecraft.world.GameRules; import net.minecraft.world.World; -public class EntityCuccoon extends LivingEntity implements IMagicals, IInAnimate { +public class CuccoonEntity extends LivingEntity implements IMagicals, IInAnimate { - private static final TrackedData STRUGGLE_COUNT = DataTracker.registerData(EntityCuccoon.class, TrackedDataHandlerRegistry.INTEGER); + private static final TrackedData STRUGGLE_COUNT = DataTracker.registerData(CuccoonEntity.class, TrackedDataHandlerRegistry.INTEGER); private final List armour = Lists.newArrayList(); private boolean captiveLastSneakState; - public EntityCuccoon(EntityType type, World world) { + public CuccoonEntity(EntityType type, World world) { super(type, world); - //width = 1.5F; - //height = 1.6F; } @Override @@ -140,9 +135,11 @@ public class EntityCuccoon extends LivingEntity implements IMagicals, IInAnimate } if (world.isClient) { - double x = this.x + width * random.nextFloat() - width/2; - double y = this.y + height * random.nextFloat(); - double z = this.z + width * random.nextFloat() - width/2; + EntityDimensions dims = getDimensions(getPose()); + + double x = this.x + dims.width * random.nextFloat() - dims.width/2; + double y = this.y + dims.height * random.nextFloat(); + double z = this.z + dims.width * random.nextFloat() - dims.width/2; world.addParticle(ParticleTypes.DRIPPING_LAVA, x, y, z, 0, 0, 0); } @@ -159,7 +156,7 @@ public class EntityCuccoon extends LivingEntity implements IMagicals, IInAnimate if (player.canConsume(false) || player.getHealth() < player.getHealthMaximum()) { DamageSource d = MagicalDamageSource.causePlayerDamage("feed", player); - IPower.spawnParticles(UParticles.CHANGELING_MAGIC, this, 7); + SpeciesList.instance().getPlayer(player).spawnParticles(UParticles.CHANGELING_MAGIC, 7); if (passenger instanceof LivingEntity) { if (player.hasStatusEffect(StatusEffects.NAUSEA)) { @@ -237,7 +234,7 @@ public class EntityCuccoon extends LivingEntity implements IMagicals, IInAnimate } @Override - protected void onDeathUpdate() { + protected void updatePostDeath() { if (++deathTime == 20) { if (!world.isClient && lastAttackedTicks > 0 && canDropLootAndXp() && world.getGameRules().getBoolean(GameRules.DO_MOB_LOOT)) { int i = getCurrentExperience(attackingPlayer); @@ -270,12 +267,12 @@ public class EntityCuccoon extends LivingEntity implements IMagicals, IInAnimate } @Override - protected void collideWithEntity(Entity entity) { - if (canBeRidden(entity)) { + protected void pushAway(Entity entity) { + if (canAddPassenger(entity)) { entity.playSound(USounds.SLIME_ADVANCE, 1, 1); entity.startRiding(this, true); } else { - super.collideWithEntity(entity); + super.pushAway(entity); } } diff --git a/src/main/java/com/minelittlepony/unicopia/entity/EntityFakeClientPlayer.java b/src/main/java/com/minelittlepony/unicopia/entity/EntityFakeClientPlayer.java deleted file mode 100644 index 095cae00..00000000 --- a/src/main/java/com/minelittlepony/unicopia/entity/EntityFakeClientPlayer.java +++ /dev/null @@ -1,84 +0,0 @@ -package com.minelittlepony.unicopia.entity; - -import javax.annotation.Nullable; - -import com.minelittlepony.unicopia.UClient; -import com.mojang.authlib.GameProfile; - -import net.minecraft.client.Minecraft; -import net.minecraft.client.entity.AbstractClientPlayer; -import net.minecraft.client.network.NetHandlerPlayClient; -import net.minecraft.client.network.NetworkPlayerInfo; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.item.ItemStack; -import net.minecraft.util.text.ITextComponent; -import net.minecraft.world.World; - -public class EntityFakeClientPlayer extends AbstractClientPlayer implements IOwned { - - private NetworkPlayerInfo playerInfo; - - private PlayerEntity owner; - - public EntityFakeClientPlayer(World world, GameProfile profile) { - super(world, profile); - } - - @Override - @Nullable - protected NetworkPlayerInfo getPlayerInfo() { - if (playerInfo == null) { - NetHandlerPlayClient connection = MinecraftClient.instance().getConnection(); - - playerInfo = connection.getPlayerInfo(getGameProfile().getId()); - - if (playerInfo == null) { - playerInfo = new NetworkPlayerInfo(getGameProfile()); - } - } - - return playerInfo; - } - - @Override - public boolean isPlayer() { - return false; - } - - @Override - protected void playEquipSound(ItemStack stack) { - /*noop*/ - } - - @Override - public boolean isUser() { - return false; - } - - @Override - public boolean getAlwaysRenderNameTag() { - return !UClient.instance().isClientPlayer(getOwner()); - } - - @Override - public boolean getAlwaysRenderNameTagForRender() { - return getAlwaysRenderNameTag(); - } - - @Override - public PlayerEntity getOwner() { - return owner; - } - - @Override - public void setOwner(PlayerEntity owner) { - this.owner = owner; - } - - @Override - public ITextComponent getDisplayName() { - ITextComponent name = super.getDisplayName(); - name.getStyle().setItalic(true); - return name; - } -} diff --git a/src/main/java/com/minelittlepony/unicopia/entity/EntityFakeServerPlayer.java b/src/main/java/com/minelittlepony/unicopia/entity/EntityFakeServerPlayer.java deleted file mode 100644 index 1ae373dd..00000000 --- a/src/main/java/com/minelittlepony/unicopia/entity/EntityFakeServerPlayer.java +++ /dev/null @@ -1,56 +0,0 @@ -package com.minelittlepony.unicopia.entity; - -import com.minelittlepony.unicopia.UClient; -import com.mojang.authlib.GameProfile; - -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.item.ItemStack; -import net.minecraft.util.text.ITextComponent; -import net.minecraft.world.WorldServer; -import net.minecraftforge.common.util.FakePlayer; - -public class EntityFakeServerPlayer extends FakePlayer implements IOwned { - - private PlayerEntity owner; - - public EntityFakeServerPlayer(WorldServer world, GameProfile profile) { - super(world, profile); - } - - @Override - public boolean isPlayer() { - return false; - } - - @Override - protected void playEquipSound(ItemStack stack) { - /*noop*/ - } - - @Override - public PlayerEntity getOwner() { - return owner; - } - - @Override - public void setOwner(PlayerEntity owner) { - this.owner = owner; - } - - @Override - public boolean getAlwaysRenderNameTag() { - return !UClient.instance().isClientPlayer(getOwner()); - } - - @Override - public boolean getAlwaysRenderNameTagForRender() { - return getAlwaysRenderNameTag(); - } - - @Override - public ITextComponent getDisplayName() { - ITextComponent name = super.getDisplayName(); - name.getStyle().setItalic(true); - return name; - } -} diff --git a/src/main/java/com/minelittlepony/unicopia/entity/EntityRacingCloud.java b/src/main/java/com/minelittlepony/unicopia/entity/EntityRacingCloud.java deleted file mode 100644 index 382127e6..00000000 --- a/src/main/java/com/minelittlepony/unicopia/entity/EntityRacingCloud.java +++ /dev/null @@ -1,75 +0,0 @@ -package com.minelittlepony.unicopia.entity; - -import java.util.List; - -import javax.annotation.Nullable; - -import com.minelittlepony.unicopia.EquinePredicates; - -import net.minecraft.entity.Entity; -import net.minecraft.entity.EntityType; -import net.minecraft.entity.LivingEntity; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.util.math.Vec3d; -import net.minecraft.world.World; - -public class EntityRacingCloud extends CloudEntity { - - public EntityRacingCloud(EntityType type, World world) { - super(type, world); - setCloudSize(1); - } - - @Override - public boolean canBeSteered() { - return true; - } - - @Override - protected boolean canFitPassenger(Entity passenger) { - return getPassengers().size() < getCloudSize(); - } - - @Override - @Nullable - public Entity getControllingPassenger() { - List list = getPassengers(); - return list.isEmpty() ? null : list.get(0); - } - - @Override - public EnumActionResult applyPlayerInteraction(PlayerEntity player, Vec3d vec, EnumHand hand) { - if (!(isBeingRidden() || isRidingOrBeingRiddenBy(player)) && hand == EnumHand.MAIN_HAND) { - if (EquinePredicates.INTERACT_WITH_CLOUDS.test(player)) { - if (!getStationary()) { - player.startRiding(this); - return EnumActionResult.SUCCESS; - } - } - } - return EnumActionResult.FAIL; - } - - @Override - public void onUpdate() { - Entity riddenByEntity = getControllingPassenger(); - - if (riddenByEntity != null && canPassengerSteer()) { - LivingEntity rider = (LivingEntity)riddenByEntity; - - double speed = 1.5F * rider.moveForward / 5; - double horizontalDriving = (riddenByEntity.rotationYaw - rider.moveStrafing * 90) * Math.PI / 180; - - motionX += -Math.sin(horizontalDriving) * speed; - motionZ += Math.cos(horizontalDriving) * speed; - - double pitch = riddenByEntity.rotationPitch * Math.PI / 180; - - motionY += -Math.sin(pitch) * (speed / 20); - } else { - motionY = 0; - } - - super.onUpdate(); - } -} diff --git a/src/main/java/com/minelittlepony/unicopia/entity/IEntity.java b/src/main/java/com/minelittlepony/unicopia/entity/IEntity.java index 21f985c9..6996dc3e 100644 --- a/src/main/java/com/minelittlepony/unicopia/entity/IEntity.java +++ b/src/main/java/com/minelittlepony/unicopia/entity/IEntity.java @@ -29,13 +29,13 @@ public interface IEntity extends InbtSerialisable, IUpdatable { } /** - * Called at the beginning of a player's update cycle. + * Called at the beginning of an update cycle. */ - void beforeUpdate(); + boolean beforeUpdate(); /** - * Event triggered when this player is hit by a projectile. + * Event triggered when this entity is hit by a projectile. */ default boolean onProjectileImpact(ProjectileEntity projectile) { return false; diff --git a/src/main/java/com/minelittlepony/unicopia/entity/AdvancedProjectileEntity.java b/src/main/java/com/minelittlepony/unicopia/entity/ProjectileEntity.java similarity index 91% rename from src/main/java/com/minelittlepony/unicopia/entity/AdvancedProjectileEntity.java rename to src/main/java/com/minelittlepony/unicopia/entity/ProjectileEntity.java index 76d3cd19..e7ccdb32 100644 --- a/src/main/java/com/minelittlepony/unicopia/entity/AdvancedProjectileEntity.java +++ b/src/main/java/com/minelittlepony/unicopia/entity/ProjectileEntity.java @@ -39,26 +39,26 @@ import net.minecraft.world.World; * * Can also carry a spell if needed. */ -public class AdvancedProjectileEntity extends ThrownItemEntity implements IMagicals, IAdvancedProjectile, ICaster { +public class ProjectileEntity extends ThrownItemEntity implements IMagicals, IAdvancedProjectile, ICaster { - private static final TrackedData DAMAGE = DataTracker.registerData(AdvancedProjectileEntity.class, TrackedDataHandlerRegistry.FLOAT); - private static final TrackedData HYDROPHOBIC = DataTracker.registerData(AdvancedProjectileEntity.class, TrackedDataHandlerRegistry.BOOLEAN); - private static final TrackedData EFFECT = DataTracker.registerData(AdvancedProjectileEntity.class, TrackedDataHandlerRegistry.TAG_COMPOUND); + private static final TrackedData DAMAGE = DataTracker.registerData(ProjectileEntity.class, TrackedDataHandlerRegistry.FLOAT); + private static final TrackedData HYDROPHOBIC = DataTracker.registerData(ProjectileEntity.class, TrackedDataHandlerRegistry.BOOLEAN); + private static final TrackedData EFFECT = DataTracker.registerData(ProjectileEntity.class, TrackedDataHandlerRegistry.TAG_COMPOUND); private final EffectSync effectDelegate = new EffectSync(this, EFFECT); private UUID ownerUuid; - public AdvancedProjectileEntity(EntityType type, World world) { + public ProjectileEntity(EntityType type, World world) { super(type, world); } - public AdvancedProjectileEntity(EntityType type, World world, LivingEntity thrower) { + public ProjectileEntity(EntityType type, World world, LivingEntity thrower) { this(type, world, thrower.x, thrower.y + thrower.getStandingEyeHeight(), thrower.z); setOwner(thrower); } - public AdvancedProjectileEntity(EntityType type, World world, double x, double y, double z) { + public ProjectileEntity(EntityType type, World world, double x, double y, double z) { super(type, world); setPosition(x, y, z); diff --git a/src/main/java/com/minelittlepony/unicopia/entity/RacingCloudEntity.java b/src/main/java/com/minelittlepony/unicopia/entity/RacingCloudEntity.java new file mode 100644 index 00000000..d7687362 --- /dev/null +++ b/src/main/java/com/minelittlepony/unicopia/entity/RacingCloudEntity.java @@ -0,0 +1,83 @@ +package com.minelittlepony.unicopia.entity; + +import java.util.List; + +import javax.annotation.Nullable; + +import com.minelittlepony.unicopia.EquinePredicates; + +import net.minecraft.entity.Entity; +import net.minecraft.entity.EntityType; +import net.minecraft.entity.LivingEntity; +import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.util.ActionResult; +import net.minecraft.util.Hand; +import net.minecraft.util.math.Vec3d; +import net.minecraft.world.World; + +public class RacingCloudEntity extends CloudEntity { + + public RacingCloudEntity(EntityType type, World world) { + super(type, world); + setCloudSize(1); + } + + @Override + public boolean canBeControlledByRider() { + return true; + } + + @Override + protected boolean canAddPassenger(Entity passenger) { + return getPassengerList().size() < getCloudSize(); + } + + @Override + @Nullable + public Entity getPrimaryPassenger() { + List list = getPassengerList(); + return list.isEmpty() ? null : list.get(0); + } + + @Override + public ActionResult interactAt(PlayerEntity player, Vec3d vec, Hand hand) { + if (!(hasPassengers() || isConnectedThroughVehicle(player)) && hand == Hand.MAIN_HAND) { + if (EquinePredicates.INTERACT_WITH_CLOUDS.test(player)) { + if (!getStationary()) { + player.startRiding(this); + return ActionResult.SUCCESS; + } + } + } + return ActionResult.FAIL; + } + + @Override + public void tick() { + Entity jockey = getPrimaryPassenger(); + + Vec3d vel = getVelocity(); + double motionX = vel.x; + double motionY = vel.y; + double motionZ = vel.z; + + if (jockey != null && canBeControlledByRider()) { + LivingEntity rider = (LivingEntity)jockey; + + double speed = 1.5F * rider.forwardSpeed / 5; + double horizontalDriving = (jockey.yaw - rider.sidewaysSpeed * 90) * Math.PI / 180; + + motionX += -Math.sin(horizontalDriving) * speed; + motionZ += Math.cos(horizontalDriving) * speed; + + double pitch = jockey.pitch * Math.PI / 180; + + motionY += -Math.sin(pitch) * (speed / 20); + } else { + motionY = 0; + } + setVelocity(motionX, motionY, motionZ); + + super.tick(); + } +} diff --git a/src/main/java/com/minelittlepony/unicopia/entity/EntitySpear.java b/src/main/java/com/minelittlepony/unicopia/entity/SpearEntity.java similarity index 55% rename from src/main/java/com/minelittlepony/unicopia/entity/EntitySpear.java rename to src/main/java/com/minelittlepony/unicopia/entity/SpearEntity.java index 63a8eac0..85ea66a6 100644 --- a/src/main/java/com/minelittlepony/unicopia/entity/EntitySpear.java +++ b/src/main/java/com/minelittlepony/unicopia/entity/SpearEntity.java @@ -1,12 +1,16 @@ package com.minelittlepony.unicopia.entity; +import com.minelittlepony.unicopia.magic.ITossedEffect; import com.minelittlepony.unicopia.projectile.IAdvancedProjectile; import com.minelittlepony.util.MagicalDamageSource; +import net.minecraft.client.network.packet.GameStateChangeS2CPacket; import net.minecraft.enchantment.EnchantmentHelper; import net.minecraft.entity.Entity; import net.minecraft.entity.EntityType; import net.minecraft.entity.LivingEntity; +import net.minecraft.entity.MovementType; +import net.minecraft.entity.damage.DamageSource; import net.minecraft.entity.data.DataTracker; import net.minecraft.entity.data.TrackedData; import net.minecraft.entity.data.TrackedDataHandlerRegistry; @@ -14,26 +18,28 @@ import net.minecraft.entity.mob.EndermanEntity; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.projectile.ArrowEntity; import net.minecraft.item.ItemStack; +import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.sound.SoundEvents; +import net.minecraft.util.hit.EntityHitResult; import net.minecraft.util.math.MathHelper; import net.minecraft.util.math.Vec3d; import net.minecraft.world.World; -public class EntitySpear extends ArrowEntity implements IAdvancedProjectile { +public class SpearEntity extends ArrowEntity implements IAdvancedProjectile { - private static final TrackedData ITEM = DataTracker.registerData(EntitySpear.class, TrackedDataHandlerRegistry.ITEM_STACK); + private static final TrackedData ITEM = DataTracker.registerData(SpearEntity.class, TrackedDataHandlerRegistry.ITEM_STACK); - private static final TrackedData KNOCKBACK = DataTracker.registerData(EntitySpear.class, TrackedDataHandlerRegistry.INTEGER); + private static final TrackedData KNOCKBACK = DataTracker.registerData(SpearEntity.class, TrackedDataHandlerRegistry.INTEGER); - public EntitySpear(EntityType type, World world) { + public SpearEntity(EntityType type, World world) { super(type, world); } - public EntitySpear(World world, double x, double y, double z) { + public SpearEntity(World world, double x, double y, double z) { super(world, x, y, z); } - public EntitySpear(World world, LivingEntity shooter) { + public SpearEntity(World world, LivingEntity shooter) { super(world, shooter); } @@ -45,54 +51,55 @@ public class EntitySpear extends ArrowEntity implements IAdvancedProjectile { } @Override - public void shoot(double x, double y, double z, float velocity, float inaccuracy) { - + public void setVelocity(double x, double y, double z, float velocity, float inaccuracy) { setDamage(0); - super.shoot(x, y, z, velocity, inaccuracy); + super.setVelocity(x, y, z, velocity, inaccuracy); } - public void move(MoverType type, double x, double y, double z) { - super.move(type, x, y, z); + @Override + public void move(MovementType type, Vec3d delta) { + super.move(type, delta); - if (type == MoverType.SELF && !inGround) { + if (type == MovementType.SELF && !inGround) { setDamage(getDamage() + 0.02); } } - public void setKnockbackStrength(int amount) { - super.setKnockbackStrength(amount); - getDataManager().set(KNOCKBACK, amount); + @Override + public void method_7449(int amount) { + super.method_7449(amount); + getDataTracker().set(KNOCKBACK, amount); } @Override - protected void onHit(RayTraceResult raytraceResultIn) { - Entity entity = raytraceResultIn.entityHit; - + protected void onEntityHit(EntityHitResult hit) { + Entity entity = hit.getEntity(); if (entity != null) { Vec3d vel = getVelocity(); double speed = vel.length(); - int damage = MathHelper.ceil(speed * getDamage()); + int damage = MathHelper.ceil(Math.max(speed * this.getDamage(), 0)); - if (getIsCritical()) { + if (isCritical()) { damage += random.nextInt(damage / 2 + 2); } - DamageSource damagesource = MagicalDamageSource.causeIndirect("spear", this, shootingEntity == null ? this : shootingEntity); + Entity archer = getOwner(); + DamageSource damagesource = MagicalDamageSource.causeIndirect("spear", this, archer == null ? this : archer); - if (isBurning() && !(entity instanceof EntityEnderman)) { - entity.setFire(5); + if (isOnFire() && !(entity instanceof EndermanEntity)) { + entity.setOnFireFor(5); } - if (entity.attackEntityFrom(damagesource, damage)) { + if (entity.damage(damagesource, damage)) { if (entity instanceof LivingEntity) { - LivingEntity entitylivingbase = (LivingEntity)entity; + LivingEntity target = (LivingEntity)entity; if (!world.isClient) { - entitylivingbase.setStuckArrows(entitylivingbase.getStuckArrows() + 1); + target.setStuckArrows(target.getStuckArrows() + 1); } int knockback = getDataTracker().get(KNOCKBACK); @@ -102,22 +109,22 @@ public class EntitySpear extends ArrowEntity implements IAdvancedProjectile { double f1 = MathHelper.sqrt(vel.x * vel.x + vel.z * vel.z); if (f1 > 0) { - entitylivingbase.addVelocity( + target.addVelocity( vel.x * knockback * 0.6000000238418579D / f1, 0.1D, vel.z * knockback * 0.6000000238418579D / f1); } } - if (shootingEntity instanceof LivingEntity) { - EnchantmentHelper.applyThornEnchantments(entitylivingbase, shootingEntity); - EnchantmentHelper.applyArthropodEnchantments((LivingEntity)shootingEntity, entitylivingbase); + if (!this.world.isClient && archer instanceof LivingEntity) { + EnchantmentHelper.onUserDamaged(target, archer); + EnchantmentHelper.onTargetDamaged((LivingEntity)archer, target); } - arrowHit(entitylivingbase); + onHit(target); - if (shootingEntity != null && entitylivingbase != shootingEntity && entitylivingbase instanceof PlayerEntity && shootingEntity instanceof ServerPlayerEntity) { - ((ServerPlayerEntity)shootingEntity).connection.sendPacket(new SPacketChangeGameState(6, 0)); + if (archer != null && target != archer && target instanceof PlayerEntity && archer instanceof ServerPlayerEntity) { + ((ServerPlayerEntity)archer).networkHandler.sendPacket(new GameStateChangeS2CPacket(6, 0)); } } @@ -130,8 +137,6 @@ public class EntitySpear extends ArrowEntity implements IAdvancedProjectile { return; } } - - super.onHit(raytraceResultIn); } @Override @@ -141,7 +146,7 @@ public class EntitySpear extends ArrowEntity implements IAdvancedProjectile { @Override public void setItem(ItemStack stack) { - getDataTracker().set(ITEM, new ItemStack(stack.getItem(), 1, stack.getMetadata())); + getDataTracker().set(ITEM, stack.copy()); } @Override @@ -166,6 +171,19 @@ public class EntitySpear extends ArrowEntity implements IAdvancedProjectile { @Override public void launch(Entity shooter, float pitch, float yaw, float pitchOffset, float velocity, float inaccuracy) { - shoot(shooter, pitch, yaw, pitchOffset, velocity, inaccuracy); + method_7474(shooter, pitch, yaw, pitchOffset, velocity, inaccuracy); + } + + @Override + public void setGravity(boolean gravity) { + } + + @Override + public void setOwner(LivingEntity owner) { + setOwner((Entity)owner); + } + + @Override + public void setEffect(ITossedEffect effect) { } } diff --git a/src/main/java/com/minelittlepony/unicopia/entity/WildCloudEntity.java b/src/main/java/com/minelittlepony/unicopia/entity/WildCloudEntity.java index 882d4186..78c026bb 100644 --- a/src/main/java/com/minelittlepony/unicopia/entity/WildCloudEntity.java +++ b/src/main/java/com/minelittlepony/unicopia/entity/WildCloudEntity.java @@ -11,7 +11,6 @@ import net.minecraft.entity.EntityData; import net.minecraft.entity.EntityType; import net.minecraft.entity.SpawnType; import net.minecraft.nbt.CompoundTag; -import net.minecraft.util.math.Box; import net.minecraft.util.math.ChunkPos; import net.minecraft.util.TypeFilterableList; import net.minecraft.util.math.BlockPos; @@ -20,7 +19,6 @@ import net.minecraft.world.IWorld; import net.minecraft.world.LocalDifficulty; import net.minecraft.world.World; import net.minecraft.world.biome.Biome.SpawnEntry; -import net.minecraft.world.chunk.Chunk; import net.minecraft.world.chunk.WorldChunk; public class WildCloudEntity extends CloudEntity { @@ -31,10 +29,10 @@ public class WildCloudEntity extends CloudEntity { public WildCloudEntity(EntityType type, World world) { super(type, world); - preventEntitySpawning = true; + inanimate = true; } - @Override + /*@Override public boolean isNotColliding() { Box boundingbox = getBoundingBox(); @@ -42,22 +40,24 @@ public class WildCloudEntity extends CloudEntity { && world.isSkyVisible(getBlockPos()) && world.doesNotCollide(this, boundingbox) && !world.intersectsFluid(boundingbox); - } + }*/ /** * Returns true if there are no solid, live entities in the specified Box, excluding the given entity * * @ref World.checkNoEntityCollision(Box area, Entity entity) */ - public boolean checkNoEntityCollision(Box area, Entity entity) { + /*public boolean checkNoEntityCollision(Box area, Entity entity) { + ServerWorld s; + ((ServerWorld)world).intersectsEntities(entity_1, voxelShape_1) for (Entity i : world.getEntities(entity, area)) { - if (!i.removed && (i.preventEntitySpawning || i instanceof CloudEntity) && (!entity.hasVehicle() || !entity.isConnectedThroughVehicle(i))) { + if (!i.removed && (i.inanimate || i instanceof CloudEntity) && (!entity.hasVehicle() || !entity.isConnectedThroughVehicle(i))) { return false; } } return true; - } + }*/ @Override public boolean canSpawn(IWorld world, SpawnType type) { @@ -93,17 +93,17 @@ public class WildCloudEntity extends CloudEntity { targetAltitude = getRandomFlyingHeight(); if (y < minSpawnHeight) { - minSpawnHeight += world.random.nextInt(Math.max(1, (int)getMaximumFlyingHeight() - (int)minSpawnHeight)); + minSpawnHeight += random.nextInt(Math.max(1, (int)getMaximumFlyingHeight() - (int)minSpawnHeight)); setPositionAndAngles(x, minSpawnHeight - 1, z, yaw, pitch); - collideWithNearbyEntities(); + moveToBoundingBoxCenter(); } - if (world.hasRain(getBlockPos())) { + if (this.world.hasRain(getBlockPos())) { setIsRaining(true); } - if (world.isThundering()) { + if (this.world.isThundering()) { setIsThundering(true); } diff --git a/src/main/java/com/minelittlepony/unicopia/entity/capabilities/IPlayer.java b/src/main/java/com/minelittlepony/unicopia/entity/capabilities/IPlayer.java index b7a8ec55..f852ef78 100644 --- a/src/main/java/com/minelittlepony/unicopia/entity/capabilities/IPlayer.java +++ b/src/main/java/com/minelittlepony/unicopia/entity/capabilities/IPlayer.java @@ -4,7 +4,7 @@ import java.util.UUID; import javax.annotation.Nullable; -import com.minelittlepony.unicopia.UClient; +import com.minelittlepony.unicopia.InteractionManager; import com.minelittlepony.unicopia.ability.IAbilityReceiver; import com.minelittlepony.unicopia.enchanting.IPageOwner; import com.minelittlepony.unicopia.entity.IFlight; @@ -132,24 +132,7 @@ public interface IPlayer extends ICaster, IRaceContainer, IOwned { @@ -23,8 +26,14 @@ public class ItemEntityCapabilities implements IRaceContainer, IOwne } @Override - public void beforeUpdate() { + public boolean beforeUpdate() { + ItemStack stack = owner.getStack(); + if (!stack.isEmpty() && stack.getItem() instanceof TickableItem) { + return ((TickableItem)stack.getItem()).onGroundTick((IItemEntity)owner) == ActionResult.SUCCESS; + } + + return false; } @Override @@ -62,4 +71,8 @@ public class ItemEntityCapabilities implements IRaceContainer, IOwne public ItemEntity getOwner() { return owner; } + + public interface TickableItem { + ActionResult onGroundTick(IItemEntity entity); + } } diff --git a/src/main/java/com/minelittlepony/unicopia/entity/capabilities/PlayerCapabilities.java b/src/main/java/com/minelittlepony/unicopia/entity/capabilities/PlayerCapabilities.java index 992a26c6..02875ef9 100644 --- a/src/main/java/com/minelittlepony/unicopia/entity/capabilities/PlayerCapabilities.java +++ b/src/main/java/com/minelittlepony/unicopia/entity/capabilities/PlayerCapabilities.java @@ -13,7 +13,7 @@ import com.minelittlepony.unicopia.UItems; import com.minelittlepony.unicopia.Unicopia; import com.minelittlepony.unicopia.ability.IAbilityReceiver; import com.minelittlepony.unicopia.enchanting.PageState; -import com.minelittlepony.unicopia.entity.EntityCuccoon; +import com.minelittlepony.unicopia.entity.CuccoonEntity; import com.minelittlepony.unicopia.entity.IFlight; import com.minelittlepony.unicopia.entity.IFood; import com.minelittlepony.unicopia.entity.IGravity; diff --git a/src/main/java/com/minelittlepony/unicopia/inventory/gui/ContainerOfHolding.java b/src/main/java/com/minelittlepony/unicopia/inventory/gui/ContainerOfHolding.java index 5437fd29..ea6b571f 100644 --- a/src/main/java/com/minelittlepony/unicopia/inventory/gui/ContainerOfHolding.java +++ b/src/main/java/com/minelittlepony/unicopia/inventory/gui/ContainerOfHolding.java @@ -6,16 +6,16 @@ import net.minecraft.entity.player.PlayerEntity; import net.minecraft.inventory.Inventory; import net.minecraft.item.ItemStack; import net.minecraft.util.Hand; +import net.minecraft.util.Identifier; +import net.minecraft.util.PacketByteBuf; public class ContainerOfHolding extends Container { - private final InventoryOfHolding inventory; private ItemStack sourceStack; - public ContainerOfHolding(PlayerEntity player) { - // TODO - super(null, 0); + public ContainerOfHolding(int num, Identifier id, PlayerEntity player, PacketByteBuf buff) { + super(null, num); sourceStack = player.getStackInHand(Hand.MAIN_HAND); inventory = InventoryOfHolding.getInventoryFromStack(sourceStack); diff --git a/src/main/java/com/minelittlepony/unicopia/inventory/gui/SpellBookContainer.java b/src/main/java/com/minelittlepony/unicopia/inventory/gui/SpellBookContainer.java index 0568b9ad..f5d5c148 100644 --- a/src/main/java/com/minelittlepony/unicopia/inventory/gui/SpellBookContainer.java +++ b/src/main/java/com/minelittlepony/unicopia/inventory/gui/SpellBookContainer.java @@ -4,7 +4,6 @@ import javax.annotation.Nonnull; import com.minelittlepony.unicopia.EquinePredicates; import com.minelittlepony.unicopia.SpeciesList; -import com.minelittlepony.unicopia.Unicopia; import com.minelittlepony.unicopia.enchanting.IPageUnlockListener; import com.minelittlepony.unicopia.magic.spells.SpellRegistry; import com.minelittlepony.unicopia.world.UWorld; @@ -17,6 +16,8 @@ import net.minecraft.inventory.BasicInventory; import net.minecraft.inventory.Inventory; import net.minecraft.item.ItemStack; import net.minecraft.particle.ParticleTypes; +import net.minecraft.recipe.Recipe; +import net.minecraft.recipe.RecipeType; import net.minecraft.sound.SoundEvents; import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; @@ -72,7 +73,10 @@ public class SpellBookContainer extends Container { ItemStack current = craftResult.getInvStack(0); if (!current.isEmpty()) { - ItemStack crafted = Unicopia.getCraftingManager().findMatchingResult(craftMatrix, worldObj); + // TODO: RecipeType.SPELL_BOOK + ItemStack crafted = player.world.getRecipeManager().getFirstMatch(RecipeType.CRAFTING, craftMatrix, worldObj) + .map(Recipe::getOutput) + .orElse(ItemStack.EMPTY); if (!crafted.isEmpty()) { resultSlot.setCrafted(true); diff --git a/src/main/java/com/minelittlepony/unicopia/inventory/gui/SpellbookResultSlot.java b/src/main/java/com/minelittlepony/unicopia/inventory/gui/SpellbookResultSlot.java index 8cbe0180..9ed3140e 100644 --- a/src/main/java/com/minelittlepony/unicopia/inventory/gui/SpellbookResultSlot.java +++ b/src/main/java/com/minelittlepony/unicopia/inventory/gui/SpellbookResultSlot.java @@ -45,7 +45,7 @@ public class SpellbookResultSlot extends SpellBookContainer.SpellbookSlot { ItemStack current = craftMatrix.getCraftResultMatrix().getInvStack(0); craftMatrix.getCraftResultMatrix().setInvStack(0, stack); - // TODO: URecipeType.GEM_ENCHANTMENT + // TODO: URecipeType.SPELL_BOOK DefaultedList remaining = player.world.getRecipeManager().getRemainingStacks(RecipeType.CRAFTING, craftMatrix, player.world); craftMatrix.getCraftResultMatrix().setInvStack(0, current); diff --git a/src/main/java/com/minelittlepony/unicopia/item/AlicornAmuletItem.java b/src/main/java/com/minelittlepony/unicopia/item/AlicornAmuletItem.java new file mode 100644 index 00000000..9ae0ca72 --- /dev/null +++ b/src/main/java/com/minelittlepony/unicopia/item/AlicornAmuletItem.java @@ -0,0 +1,297 @@ +package com.minelittlepony.unicopia.item; + +import java.util.List; +import java.util.UUID; + +import javax.annotation.Nullable; + +import com.google.common.collect.Multimap; +import com.minelittlepony.unicopia.InteractionManager; +import com.minelittlepony.unicopia.SpeciesList; +import com.minelittlepony.unicopia.UItems; +import com.minelittlepony.unicopia.ducks.IItemEntity; +import com.minelittlepony.unicopia.entity.capabilities.IPlayer; +import com.minelittlepony.unicopia.magic.Affinity; +import com.minelittlepony.unicopia.magic.items.IDependable; +import com.minelittlepony.unicopia.world.UWorld; +import com.minelittlepony.util.MagicalDamageSource; +import com.minelittlepony.util.VecHelper; +import com.minelittlepony.unicopia.entity.capabilities.ItemEntityCapabilities; + + +import net.minecraft.util.ChatUtil; +import net.fabricmc.api.EnvType; +import net.fabricmc.api.Environment; +import net.minecraft.client.item.TooltipContext; +import net.minecraft.entity.Entity; +import net.minecraft.entity.EquipmentSlot; +import net.minecraft.entity.ItemEntity; +import net.minecraft.entity.MovementType; +import net.minecraft.entity.attribute.EntityAttributeModifier; +import net.minecraft.entity.attribute.EntityAttributes; +import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.item.ArmorItem; +import net.minecraft.item.ArmorMaterial; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.CompoundTag; +import net.minecraft.particle.ParticleEffect; +import net.minecraft.particle.ParticleTypes; +import net.minecraft.recipe.Ingredient; +import net.minecraft.sound.SoundCategory; +import net.minecraft.sound.SoundEvent; +import net.minecraft.sound.SoundEvents; +import net.minecraft.text.Text; +import net.minecraft.text.TranslatableText; +import net.minecraft.util.ActionResult; +import net.minecraft.util.Hand; +import net.minecraft.util.TypedActionResult; +import net.minecraft.util.math.Vec3d; +import net.minecraft.world.LocalDifficulty; +import net.minecraft.world.World; +import net.minecraft.world.explosion.Explosion.DestructionType; + +public class AlicornAmuletItem extends ArmorItem implements IDependable, ItemEntityCapabilities.TickableItem { + + private static final UUID[] MODIFIERS = new UUID[] { + UUID.fromString("845DB27C-C624-495F-8C9F-6020A9A58B6B"), + UUID.fromString("D8499B04-0E66-4726-AB29-64469D734E0D"), + UUID.fromString("9F3D476D-C118-4544-8365-64846904B48E"), + UUID.fromString("2AD3F246-FEE1-4E67-B886-69FD380BB150") + }; + + public AlicornAmuletItem() { + super(new Material(), EquipmentSlot.CHEST, new Settings().maxCount(1)); + } + + @Override + public Affinity getAffinity() { + return Affinity.BAD; + } + + + @Override + public ActionResult onGroundTick(IItemEntity item) { + + ItemEntity entity = item.getRaceContainer().getOwner(); + + World world = entity.world; + + double x = entity.x + world.random.nextFloat() - 0.5; + double z = entity.z + world.random.nextFloat() - 0.5; + double y = entity.y + world.random.nextFloat(); + + ParticleEffect particle = world.random.nextBoolean() ? ParticleTypes.LARGE_SMOKE : ParticleTypes.FLAME; + + world.addParticle(particle, x, y, z, 0, 0, 0); + + if (world.random.nextInt(500) == 0) { + world.playSound(null, entity.getBlockPos(), SoundEvents.AMBIENT_CAVE, SoundCategory.HOSTILE, 0.5F, 1); + } + + Vec3d position = entity.getPos(); + VecHelper.findAllEntitiesInRange(entity, world, entity.getBlockPos(), 10) + .filter(e -> e instanceof PlayerEntity) + .sorted((a, b) -> (int)(a.getPos().distanceTo(position) - b.getPos().distanceTo(position))) + .findFirst() + .ifPresent(player -> interactWithPlayer(entity, (PlayerEntity)player)); + + return ActionResult.PASS; + } + + protected void interactWithPlayer(ItemEntity entity, PlayerEntity player) { + + entity.move(MovementType.SELF, player.getPos().subtract(entity.getPos()).multiply(0.02)); + + if (!player.world.isClient && !entity.removed) { + if (player.getPos().distanceTo(entity.getPos()) < 3) { + if (entity.world.random.nextInt(150) == 0) { + + TypedActionResult result = use(player.world, player, Hand.MAIN_HAND); + + if (result.getResult() == ActionResult.SUCCESS) { + entity.setPickupDelay(1000); + entity.remove(); + } + } + } + } + } + + @Environment(EnvType.CLIENT) + @Override + public void appendTooltip(ItemStack stack, @Nullable World world, List tooltip, TooltipContext context) { + + IPlayer iplayer = InteractionManager.instance().getIPlayer(); + + if (iplayer != null) { + int attachedTime = iplayer.getInventory().getTicksAttached(this); + if (attachedTime > 0) { + tooltip.add(new TranslatableText(getTranslationKey() + ".tagline", ChatUtil.ticksToString(attachedTime))); + } + } + } + + @Override + public Text getName(ItemStack stack) { + if (!stack.hasTag()) { + stack.setTag(new CompoundTag()); + } + + CompoundTag compound = stack.getTag(); + + int hideFlags = 0; + + if (!compound.containsKey("HideFlags") || ((hideFlags = compound.getInt("HideFlags")) & 2) == 0) { + compound.putInt("HideFlags", hideFlags | 2); + } + + return super.getName(stack); + } + + @Override + public void inventoryTick(ItemStack stack, World world, Entity entity, int slot, boolean selected) { + if (!(entity instanceof PlayerEntity)) { + return; + } + + PlayerEntity player = (PlayerEntity)entity; + + if (player.getHealth() < player.getHealthMaximum()) { + player.heal(0.5F); + } else if (player.canConsume(false)) { + player.getHungerManager().add(1, 0); + } + + IPlayer iplayer = SpeciesList.instance().getPlayer(player); + + float attachedTime = iplayer.getInventory().getTicksAttached(this); + + if (iplayer.getExertion() < 1) { + iplayer.addExertion(2); + } + + if (iplayer.getEnergy() < 0.005F + (attachedTime / 1000000)) { + iplayer.addEnergy(2); + } + + if (attachedTime == 1) { + world.playSound(null, player.getBlockPos(), SoundEvents.ENTITY_ELDER_GUARDIAN_CURSE, SoundCategory.PLAYERS, 3, 1); + } + + if (attachedTime > 0 && attachedTime % 100 == 0) { + world.playSound(null, player.getBlockPos(), SoundEvents.MUSIC_NETHER, SoundCategory.PLAYERS, 3, 1); + } + + if (attachedTime > 1000) { + if (world.random.nextInt(700) == 0) { + player.dropSelectedItem(false); + } + } + + if (attachedTime > 3000) { + if (world.random.nextInt(300) == 0) { + player.addVelocity(world.random.nextFloat() - 0.5F, 0, 0); + } + + if (world.random.nextInt(300) == 0) { + player.addVelocity(0, 0, world.random.nextFloat() - 0.5F); + } + } + + if (attachedTime > 6000) { + if (world.random.nextInt(300) == 0) { + player.yaw += 180; + } + } + + if (attachedTime > 13000) { + if (world.random.nextInt(300) == 0) { + player.damage(MagicalDamageSource.ALICORN_AMULET, 1F); + } + } + + if (stack.getDamage() >= getMaxDamage() - 1) { + stack.damage(10, player, p -> p.sendEquipmentBreakStatus(EquipmentSlot.CHEST)); + + player.damage(MagicalDamageSource.ALICORN_AMULET, player.getHealthMaximum() - 0.01F); + player.getHungerManager().setFoodLevel(1); + + Vec3d pos = player.getPos(); + + player.world.createExplosion(player, pos.x, pos.y, pos.z, 10, DestructionType.NONE); + + UWorld.scheduleTask(w -> { + w.createExplosion(player, pos.x, pos.y, pos.z, 6, DestructionType.BREAK); + }, 50); + } + + iplayer.getInventory().enforceDependency(this); + } + + @Override + public void onRemoved(IPlayer player, float needfulness) { + + float attachedTime = player.getInventory().getTicksAttached(this) / 100F; + + LocalDifficulty difficulty = player.getWorld().getLocalDifficulty(player.getOrigin()); + float amount = (attachedTime * (1 + needfulness)) * (1 + difficulty.getClampedLocalDifficulty()); + + amount = Math.min(amount, player.getOwner().getHealthMaximum()); + + player.getOwner().damage(MagicalDamageSource.ALICORN_AMULET, amount); + + if (attachedTime > 120) { + player.getOwner().takeKnockback(player.getOwner(), 1, 1, 1); + } + } + + @Override + public Multimap getModifiers(EquipmentSlot equipmentSlot) { + Multimap multimap = super.getModifiers(equipmentSlot); + + if (equipmentSlot == slot) { + UUID modifierId = MODIFIERS[equipmentSlot.getEntitySlotId()]; + multimap.put(EntityAttributes.ATTACK_DAMAGE.getId(), new EntityAttributeModifier(modifierId, "Strength modifier", 50, EntityAttributeModifier.Operation.ADDITION)); + } + + return multimap; + } + + static class Material implements ArmorMaterial { + + @Override + public int getDurability(EquipmentSlot slot) { + return 200; + } + + @Override + public int getProtectionAmount(EquipmentSlot slot) { + return Integer.MAX_VALUE; + } + + @Override + public int getEnchantability() { + return 0; + } + + @Override + public SoundEvent getEquipSound() { + return SoundEvents.ITEM_ARMOR_EQUIP_IRON; + } + + @Override + public Ingredient getRepairIngredient() { + return Ingredient.ofItems(UItems.alicorn_amulet); + } + + @Override + public String getName() { + return "alicorn_amulet"; + } + + @Override + public float getToughness() { + return 20; + } + } +} diff --git a/src/main/java/com/minelittlepony/unicopia/item/AppleItem.java b/src/main/java/com/minelittlepony/unicopia/item/AppleItem.java index 50f8382f..2b93e6ee 100644 --- a/src/main/java/com/minelittlepony/unicopia/item/AppleItem.java +++ b/src/main/java/com/minelittlepony/unicopia/item/AppleItem.java @@ -6,6 +6,8 @@ import java.util.function.Supplier; import javax.annotation.Nullable; import com.minelittlepony.unicopia.UItems; +import com.minelittlepony.unicopia.ducks.IItemEntity; +import com.minelittlepony.unicopia.entity.capabilities.ItemEntityCapabilities; import com.minelittlepony.unicopia.item.consumables.IEdible; import com.minelittlepony.unicopia.item.consumables.Toxicity; import com.minelittlepony.util.collection.Pool; @@ -23,10 +25,11 @@ import net.minecraft.particle.ParticleTypes; import net.minecraft.tag.BlockTags; import net.minecraft.text.LiteralText; import net.minecraft.text.Text; +import net.minecraft.util.ActionResult; import net.minecraft.util.math.MathHelper; import net.minecraft.world.World; -public class AppleItem extends Item implements IEdible { +public class AppleItem extends Item implements IEdible, ItemEntityCapabilities.TickableItem { private static final Pool>> typeVariantMap = Pool.of(PlanksBlock.Type.OAK, PlanksBlock.Type.OAK, new Weighted>() @@ -71,38 +74,39 @@ public class AppleItem extends Item implements IEdible { } @Override - public boolean onEntityItemUpdate(ItemEntity item) { + public ActionResult onGroundTick(IItemEntity item) { + ItemEntity entity = item.getRaceContainer().getOwner(); - if (!item.removed && item.age > item.pickupDelay) { + if (!entity.removed && item.getAge() > item.getPickupDelay()) { - if (!item.world.isClient) { - item.remove(); + if (!entity.world.isClient) { + entity.remove(); - ItemEntity neu = EntityType.ITEM.create(item.world); - neu.copyPositionAndRotation(item); - neu.setStack(new ItemStack(UItems.rotten_apple)); + ItemEntity neu = EntityType.ITEM.create(entity.world); + neu.copyPositionAndRotation(entity); + neu.setStack(new ItemStack(UItems.rotten_apple)); - item.world.spawnEntity(neu); + entity.world.spawnEntity(neu); - ItemEntity copy = EntityType.ITEM.create(item.world); - copy.copyPositionAndRotation(item); - copy.setStack(item.getStack()); - copy.getStack().decrement(1); + ItemEntity copy = EntityType.ITEM.create(entity.world); + copy.copyPositionAndRotation(entity); + copy.setStack(entity.getStack()); + copy.getStack().decrement(1); - item.world.spawnEntity(copy); - } else { - float bob = MathHelper.sin(((float)item.getAge() + 1) / 10F + item.hoverHeight) * 0.1F + 0.1F; + entity.world.spawnEntity(copy); + } else { + float bob = MathHelper.sin(((float)item.getAge() + 1) / 10F + entity.hoverHeight) * 0.1F + 0.1F; - for (int i = 0; i < 3; i++) { - item.world.addParticle(ParticleTypes.AMBIENT_ENTITY_EFFECT, item.x, item.y + bob, item.z, - item.world.random.nextGaussian() - 0.5F, - item.world.random.nextGaussian() - 0.5F, - item.world.random.nextGaussian() - 0.5F); - } + for (int i = 0; i < 3; i++) { + entity.world.addParticle(ParticleTypes.AMBIENT_ENTITY_EFFECT, entity.x, entity.y + bob, entity.z, + entity.world.random.nextGaussian() - 0.5F, + entity.world.random.nextGaussian() - 0.5F, + entity.world.random.nextGaussian() - 0.5F); } } + } - return false; + return ActionResult.PASS; } @Override diff --git a/src/main/java/com/minelittlepony/unicopia/item/BagOfHoldingItem.java b/src/main/java/com/minelittlepony/unicopia/item/BagOfHoldingItem.java new file mode 100644 index 00000000..a4e8a63a --- /dev/null +++ b/src/main/java/com/minelittlepony/unicopia/item/BagOfHoldingItem.java @@ -0,0 +1,153 @@ +package com.minelittlepony.unicopia.item; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import javax.annotation.Nullable; + +import com.minelittlepony.unicopia.EquinePredicates; +import com.minelittlepony.unicopia.UContainers; +import com.minelittlepony.unicopia.inventory.gui.InventoryOfHolding; +import com.minelittlepony.unicopia.magic.Affinity; +import com.minelittlepony.unicopia.magic.items.IMagicalItem; +import com.minelittlepony.util.VecHelper; + +import net.fabricmc.fabric.api.container.ContainerProviderRegistry; +import net.minecraft.block.entity.BlockEntity; +import net.minecraft.client.item.TooltipContext; +import net.minecraft.container.Container; +import net.minecraft.container.NameableContainerProvider; +import net.minecraft.entity.Entity; +import net.minecraft.entity.ItemEntity; +import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.entity.player.PlayerInventory; +import net.minecraft.inventory.Inventory; +import net.minecraft.item.Item; +import net.minecraft.item.ItemGroup; +import net.minecraft.item.ItemStack; +import net.minecraft.sound.SoundEvents; +import net.minecraft.text.Text; +import net.minecraft.text.TranslatableText; +import net.minecraft.util.ActionResult; +import net.minecraft.util.Hand; +import net.minecraft.util.TypedActionResult; +import net.minecraft.util.hit.BlockHitResult; +import net.minecraft.util.hit.HitResult; +import net.minecraft.util.math.Box; +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.World; + +public class BagOfHoldingItem extends Item implements IMagicalItem { + + public BagOfHoldingItem() { + super(new Settings().maxCount(1).group(ItemGroup.TRANSPORTATION)); + } + + @Override + public void appendTooltip(ItemStack stack, @Nullable World worldIn, List tooltip, TooltipContext flagIn) { + super.appendTooltip(stack, worldIn, tooltip, flagIn); + + Map counts = new HashMap<>(); + + InventoryOfHolding.iterateContents(stack, (i, itemstack) -> { + Text name = itemstack.getName(); + + counts.put(name, counts.getOrDefault(name, 0) + itemstack.getCount()); + return true; + }); + + for (Text name : counts.keySet()) { + tooltip.add(name.append(" ").append(counts.get(name).toString())); + } + } + + @Override + public TypedActionResult use(World world, PlayerEntity player, Hand hand) { + + if (!EquinePredicates.MAGI.test(player)) { + return super.use(world, player, hand); + } + + ItemStack stack = player.getStackInHand(hand); + + if (player.isSneaking()) { + HitResult hit = VecHelper.getObjectMouseOver(player, 5, 0); + + if (hit != null) { + if (hit.getType() == HitResult.Type.BLOCK) { + BlockHitResult bhit = (BlockHitResult)hit; + BlockPos pos = bhit.getBlockPos(); + + BlockEntity tile = world.getBlockEntity(pos); + + if (tile instanceof Inventory) { + InventoryOfHolding inventory = InventoryOfHolding.getInventoryFromStack(stack); + + inventory.addBlockEntity(world, pos, (BlockEntity & Inventory)tile); + inventory.writeTostack(stack); + inventory.onInvClose(player); + + return new TypedActionResult<>(ActionResult.SUCCESS, stack); + } + + Box box = new Box(pos.offset(bhit.getSide())).expand(0.5); + + List itemsAround = world.getEntities(player, box, EquinePredicates.ITEMS); + + if (itemsAround.size() > 0) { + InventoryOfHolding inventory = InventoryOfHolding.getInventoryFromStack(stack); + + inventory.addItem((ItemEntity)itemsAround.get(0)); + inventory.writeTostack(stack); + inventory.onInvClose(player); + + return new TypedActionResult<>(ActionResult.SUCCESS, stack); + } + } + } + + return new TypedActionResult<>(ActionResult.FAIL, stack); + } + + ContainerProviderRegistry.INSTANCE.openContainer(UContainers.BAG_OF_HOLDING, player, o -> {}); + player.openContainer(new ContainerProvider(stack)); + + player.playSound(SoundEvents.BLOCK_ENDER_CHEST_OPEN, 0.5F, 1); + + return new TypedActionResult<>(ActionResult.SUCCESS, stack); + } + + @Override + public Affinity getAffinity() { + return Affinity.NEUTRAL; + } + + @Override + public boolean hasInnerSpace() { + return true; + } + + class ContainerProvider implements NameableContainerProvider { + + private Text customname = null; + + ContainerProvider(ItemStack stack) { + if (stack.hasCustomName()) { + customname = stack.getName(); + } + } + + @Override + public Text getDisplayName() { + if (customname != null) { + return customname; + } + return new TranslatableText("unicopi.gui.title.itemofholding"); + } + + @Override + public Container createMenu(int id, PlayerInventory playerInventory, PlayerEntity player) { + return null; + } + } +} diff --git a/src/main/java/com/minelittlepony/unicopia/item/CloudPlacerItem.java b/src/main/java/com/minelittlepony/unicopia/item/CloudPlacerItem.java index 5aa5c829..ad1609bd 100644 --- a/src/main/java/com/minelittlepony/unicopia/item/CloudPlacerItem.java +++ b/src/main/java/com/minelittlepony/unicopia/item/CloudPlacerItem.java @@ -1,11 +1,10 @@ package com.minelittlepony.unicopia.item; -import java.util.function.Function; - import com.minelittlepony.unicopia.entity.CloudEntity; import com.minelittlepony.unicopia.magic.items.IDispensable; import net.minecraft.block.DispenserBlock; +import net.minecraft.entity.EntityType; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.item.Item; import net.minecraft.item.ItemGroup; @@ -23,20 +22,20 @@ import net.minecraft.world.World; public class CloudPlacerItem extends Item implements IDispensable { - private final Function cloudSupplier; + private final EntityType cloudSupplier; - public CloudPlacerItem(Function cloudSupplier) { + public CloudPlacerItem(EntityType spawner) { super(new Item.Settings() .group(ItemGroup.MATERIALS) .maxCount(16) ); - this.cloudSupplier = cloudSupplier; + this.cloudSupplier = spawner; setDispenseable(); } public void placeCloud(World world, BlockPos pos) { - CloudEntity cloud = cloudSupplier.apply(world); + CloudEntity cloud = cloudSupplier.create(world); cloud.setPositionAndAngles(pos, 0, 0); world.spawnEntity(cloud); } diff --git a/src/main/java/com/minelittlepony/unicopia/item/CursedMagicGemItem.java b/src/main/java/com/minelittlepony/unicopia/item/CursedMagicGemItem.java index f818326b..06ad1366 100644 --- a/src/main/java/com/minelittlepony/unicopia/item/CursedMagicGemItem.java +++ b/src/main/java/com/minelittlepony/unicopia/item/CursedMagicGemItem.java @@ -3,7 +3,7 @@ package com.minelittlepony.unicopia.item; import com.minelittlepony.unicopia.magic.Affinity; import com.minelittlepony.unicopia.magic.IDispenceable; import com.minelittlepony.unicopia.magic.IMagicEffect; -import com.minelittlepony.unicopia.magic.spells.SpellCastResult; +import com.minelittlepony.unicopia.magic.spells.CastResult; import com.minelittlepony.util.MagicalDamageSource; import net.minecraft.item.ItemStack; @@ -16,20 +16,20 @@ import net.minecraft.world.explosion.Explosion.DestructionType; public class CursedMagicGemItem extends MagicGemItem { @Override - public SpellCastResult onDispenseSpell(BlockPointer source, ItemStack stack, IDispenceable effect) { + public CastResult onDispenseSpell(BlockPointer source, ItemStack stack, IDispenceable effect) { BlockPos pos = source.getBlockPos(); World world = source.getWorld(); - SpellCastResult result = super.onDispenseSpell(source, stack, effect); + CastResult result = super.onDispenseSpell(source, stack, effect); - if (result != SpellCastResult.NONE) { + if (result != CastResult.NONE) { if (world.random.nextInt(200) == 0) { float strength = world.random.nextFloat() * 100; world.createExplosion(null, pos.getX(), pos.getY(), pos.getZ(), strength, DestructionType.DESTROY); - return SpellCastResult.NONE; + return CastResult.NONE; } } @@ -37,10 +37,10 @@ public class CursedMagicGemItem extends MagicGemItem { } @Override - public SpellCastResult onCastSpell(ItemUsageContext context, IMagicEffect effect) { - SpellCastResult result = super.onCastSpell(context, effect); + public CastResult onCastSpell(ItemUsageContext context, IMagicEffect effect) { + CastResult result = super.onCastSpell(context, effect); - if (result != SpellCastResult.NONE) { + if (result != CastResult.NONE) { context.getPlayer().damage(MagicalDamageSource.causePlayerDamage("corruption", context.getPlayer()), 1); } diff --git a/src/main/java/com/minelittlepony/unicopia/item/EnchantedStaffItem.java b/src/main/java/com/minelittlepony/unicopia/item/EnchantedStaffItem.java new file mode 100644 index 00000000..f28c00ac --- /dev/null +++ b/src/main/java/com/minelittlepony/unicopia/item/EnchantedStaffItem.java @@ -0,0 +1,152 @@ +package com.minelittlepony.unicopia.item; + +import java.util.List; + +import javax.annotation.Nonnull; +import javax.annotation.Nullable; + +import com.minelittlepony.unicopia.EquinePredicates; +import com.minelittlepony.unicopia.SpeciesList; +import com.minelittlepony.unicopia.entity.capabilities.IPlayer; +import com.minelittlepony.unicopia.magic.Affinity; +import com.minelittlepony.unicopia.magic.CasterUtils; +import com.minelittlepony.unicopia.magic.IAffine; +import com.minelittlepony.unicopia.magic.ICaster; +import com.minelittlepony.unicopia.magic.ITossedEffect; +import com.minelittlepony.unicopia.projectile.ITossableItem; + +import net.minecraft.block.BlockState; +import net.minecraft.client.item.TooltipContext; +import net.minecraft.entity.Entity; +import net.minecraft.entity.EquipmentSlot; +import net.minecraft.entity.LivingEntity; +import net.minecraft.entity.damage.DamageSource; +import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.item.ItemStack; +import net.minecraft.particle.ParticleTypes; +import net.minecraft.sound.SoundCategory; +import net.minecraft.sound.SoundEvents; +import net.minecraft.text.Text; +import net.minecraft.util.ActionResult; +import net.minecraft.util.Hand; +import net.minecraft.util.TypedActionResult; +import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.Vec3d; +import net.minecraft.world.World; + +public class EnchantedStaffItem extends StaffItem implements IAffine, ITossableItem { + + @Nonnull + private final ITossedEffect effect; + + public EnchantedStaffItem(Settings settings, @Nonnull ITossedEffect effect) { + super(settings.maxDamage(500)); + + this.effect = effect; + } + + @Override + public void appendTooltip(ItemStack stack, @Nullable World world, List tooltip, TooltipContext context) { + tooltip.add(getAffinity().getName()); + } + + @Override + public TypedActionResult use(World world, PlayerEntity player, Hand hand) { + if (EquinePredicates.MAGI.test(player) && hand == Hand.MAIN_HAND) { + ItemStack itemstack = player.getStackInHand(hand); + + player.swingHand(hand); + + return new TypedActionResult<>(ActionResult.SUCCESS, itemstack); + } + + return super.use(world, player, hand); + } + + @Override + public void onStoppedUsing(ItemStack itemstack, World world, LivingEntity entity, int timeLeft) { + if (EquinePredicates.MAGI.test(entity) && entity instanceof PlayerEntity) { + + int i = getMaxUseTime(itemstack) - timeLeft; + + if (i > 10 && canBeThrown(itemstack)) { + toss(world, itemstack, (PlayerEntity)entity); + } + } + } + + @Override + protected boolean castContainedEffect(ItemStack stack, LivingEntity target, LivingEntity attacker) { + if (attacker.isSneaking()) { + stack.damage(50, attacker, p -> p.sendEquipmentBreakStatus(EquipmentSlot.MAINHAND)); + + CasterUtils.toCaster(attacker).ifPresent(c -> c.subtractEnergyCost(4)); + CasterUtils.toCaster(target).ifPresent(c -> onImpact( + c, + target.getBlockPos(), + target.getEntityWorld().getBlockState(target.getBlockPos()) + )); + + return true; + } + + return false; + } + + public void onUpdate(ItemStack stack, World world, Entity entity, int itemSlot, boolean isSelected) { + + if (entity instanceof LivingEntity) { + LivingEntity living = (LivingEntity)entity; + + if (living.getActiveItem().getItem() == this) { + Vec3d eyes = entity.getCameraPosVec(1); + + float i = getMaxUseTime(stack) - living.getItemUseTimeLeft(); + + world.addParticle(i > 150 ? ParticleTypes.LARGE_SMOKE : ParticleTypes.CLOUD, eyes.x, eyes.y, eyes.z, + (world.random.nextGaussian() - 0.5) / 10, + (world.random.nextGaussian() - 0.5) / 10, + (world.random.nextGaussian() - 0.5) / 10 + ); + world.playSound(null, entity.getBlockPos(), SoundEvents.ENTITY_GUARDIAN_ATTACK, SoundCategory.PLAYERS, 1, i / 20); + + if (i > 200) { + living.clearActiveItem(); + living.damage(DamageSource.MAGIC, 1200); + CasterUtils.toCaster(entity).ifPresent(c -> onImpact( + c, + entity.getBlockPos(), + entity.getEntityWorld().getBlockState(entity.getBlockPos()) + )); + } + } + } + + } + + @Override + public int getMaxUseTime(ItemStack stack) { + return 72000; + } + + @Override + public void toss(World world, ItemStack stack, PlayerEntity player) { + IPlayer iplayer = SpeciesList.instance().getPlayer(player); + + iplayer.subtractEnergyCost(4); + effect.toss(iplayer); + + stack.damage(1, player, p -> p.sendEquipmentBreakStatus(EquipmentSlot.MAINHAND)); + } + + @Override + public void onImpact(ICaster caster, BlockPos pos, BlockState state) { + effect.onImpact(caster, pos, state); + } + + @Override + public Affinity getAffinity() { + return effect.getAffinity(); + } + +} diff --git a/src/main/java/com/minelittlepony/unicopia/item/ItemAlicornAmulet.java b/src/main/java/com/minelittlepony/unicopia/item/ItemAlicornAmulet.java deleted file mode 100644 index 3f858c62..00000000 --- a/src/main/java/com/minelittlepony/unicopia/item/ItemAlicornAmulet.java +++ /dev/null @@ -1,262 +0,0 @@ -package com.minelittlepony.unicopia.item; - -import java.util.List; -import java.util.UUID; - -import javax.annotation.Nullable; - -import com.google.common.collect.HashMultimap; -import com.google.common.collect.Multimap; -import com.minelittlepony.unicopia.SpeciesList; -import com.minelittlepony.unicopia.UClient; -import com.minelittlepony.unicopia.entity.capabilities.IPlayer; -import com.minelittlepony.unicopia.magic.items.IDependable; -import com.minelittlepony.unicopia.spell.SpellAffinity; -import com.minelittlepony.unicopia.world.UWorld; -import com.minelittlepony.util.MagicalDamageSource; -import com.minelittlepony.util.VecHelper; -import com.minelittlepony.util.lang.ClientLocale; - -import net.minecraft.client.util.ITooltipFlag; -import net.minecraft.entity.Entity; -import net.minecraft.entity.MoverType; -import net.minecraft.entity.SharedMonsterAttributes; -import net.minecraft.entity.ai.attributes.AttributeModifier; -import net.minecraft.entity.item.EntityItem; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.init.SoundEvents; -import net.minecraft.inventory.EntityEquipmentSlot; -import net.minecraft.item.ItemArmor; -import net.minecraft.item.ItemStack; -import net.minecraft.nbt.CompoundTag; -import net.minecraft.util.ActionResult; -import net.minecraft.util.DamageSource; -import net.minecraft.util.EnumActionResult; -import net.minecraft.util.EnumHand; -import net.minecraft.util.EnumParticleTypes; -import net.minecraft.util.SoundCategory; -import net.minecraft.util.StringUtils; -import net.minecraft.util.math.Vec3d; -import net.minecraft.world.DifficultyInstance; -import net.minecraft.world.World; - -public class ItemAlicornAmulet extends ItemArmor implements IDependable { - - public static final DamageSource DAMAGE_SOURCE = MagicalDamageSource.create("alicorn_amulet") - .setDamageBypassesArmor() - .setDamageIsAbsolute(); - - private static final UUID[] ARMOR_MODIFIERS = new UUID[] { - UUID.fromString("845DB27C-C624-495F-8C9F-6020A9A58B6B"), - UUID.fromString("D8499B04-0E66-4726-AB29-64469D734E0D"), - UUID.fromString("9F3D476D-C118-4544-8365-64846904B48E"), - UUID.fromString("2AD3F246-FEE1-4E67-B886-69FD380BB150") - }; - - public ItemAlicornAmulet(String domain, String name) { - super(ArmorMaterial.GOLD, 1, EntityEquipmentSlot.CHEST); - - setTranslationKey(name); - setRegistryName(domain, name); - } - - @Override - public SpellAffinity getAffinity() { - return SpellAffinity.BAD; - } - - @Override - public boolean getIsRepairable(ItemStack toRepair, ItemStack repair) { - return toRepair.getItem() == repair.getItem(); - } - - @Override - public boolean onEntityItemUpdate(EntityItem entity) { - - World world = entity.world; - - double x = entity.posX + world.rand.nextFloat() - 0.5; - double z = entity.posZ + world.rand.nextFloat() - 0.5; - double y = entity.posY + world.rand.nextFloat(); - - EnumParticleTypes particle = world.rand.nextBoolean() ? EnumParticleTypes.SMOKE_LARGE : EnumParticleTypes.FLAME; - - world.spawnParticle(particle, x, y, z, 0, 0, 0); - - if (world.rand.nextInt(500) == 0) { - world.playSound(null, entity.getPosition(), SoundEvents.AMBIENT_CAVE, SoundCategory.HOSTILE, 0.5F, 1); - } - - Vec3d position = entity.getPositionVector(); - VecHelper.findAllEntitiesInRange(entity, world, entity.getPosition(), 10) - .filter(e -> e instanceof PlayerEntity) - .sorted((a, b) -> (int)(a.getPositionVector().distanceTo(position) - b.getPositionVector().distanceTo(position))) - .findFirst() - .ifPresent(player -> interactWithPlayer(entity, (PlayerEntity)player)); - - return false; - } - - protected void interactWithPlayer(EntityItem entity, PlayerEntity player) { - double diffX = player.posX - entity.posX; - double diffY = player.posY - entity.posY; - double diffZ = player.posZ - entity.posZ; - - entity.move(MoverType.SELF, diffX / 50, diffY / 50, diffZ / 50); - - if (!player.world.isClient && !entity.isDead) { - if (player.getPositionVector().distanceTo(entity.getPositionVector()) < 3) { - if (entity.world.rand.nextInt(150) == 0) { - - TypedActionResult result = onItemRightClick(player.world, player, EnumHand.MAIN_HAND); - - if (result.getType() == EnumActionResult.SUCCESS) { - entity.setPickupDelay(1000); - entity.setDead(); - } - } - } - } - } - - @Override - public void addInformation(ItemStack stack, @Nullable World worldIn, List tooltip, ITooltipFlag flagIn) { - IPlayer iplayer = UClient.instance().getIPlayer(); - - if (iplayer != null) { - int attachedTime = iplayer.getInventory().getTicksAttached(this); - if (attachedTime > 0) { - tooltip.add(ClientLocale.format(getTranslationKey() + ".tagline", StringUtils.ticksToElapsedTime(attachedTime))); - } - } - } - - @Override - public String getItemStackDisplayName(ItemStack stack) { - - if (!stack.hasTagCompound()) { - stack.setTagCompound(new CompoundTag()); - } - - CompoundTag compound = stack.getTagCompound(); - - int hideFlags = 0; - - if (!compound.hasKey("HideFlags") || ((hideFlags = compound.getInteger("HideFlags")) & 2) == 0) { - compound.setInteger("HideFlags", hideFlags | 2); - } - - return super.getItemStackDisplayName(stack); - } - - @Override - public void onArmorTick(World world, PlayerEntity player, ItemStack itemStack) { - if (player.getHealth() < player.getMaxHealth()) { - player.heal(0.5F); - } else if (player.canEat(false)) { - player.getFoodStats().addStats(1, 0); - } - - IPlayer iplayer = SpeciesList.instance().getPlayer(player); - - float attachedTime = iplayer.getInventory().getTicksAttached(this); - - if (iplayer.getExertion() < 1) { - iplayer.addExertion(2); - } - - if (iplayer.getEnergy() < 0.005F + (attachedTime / 1000000)) { - iplayer.addEnergy(2); - } - - if (attachedTime == 1) { - world.playSound(null, player.getPosition(), SoundEvents.ENTITY_ELDER_GUARDIAN_CURSE, SoundCategory.PLAYERS, 3, 1); - } - - if (attachedTime > 0 && attachedTime % 100 == 0) { - world.playSound(null, player.getPosition(), SoundEvents.MUSIC_NETHER, SoundCategory.PLAYERS, 3, 1); - } - - if (attachedTime > 1000) { - if (world.rand.nextInt(700) == 0) { - player.dropItem(false); - } - } - - if (attachedTime > 3000) { - if (world.rand.nextInt(300) == 0) { - player.motionX += world.rand.nextFloat() - 0.5F; - } - - if (world.rand.nextInt(300) == 0) { - player.motionZ += world.rand.nextFloat() - 0.5F; - } - } - - if (attachedTime > 6000) { - if (world.rand.nextInt(300) == 0) { - player.rotationYaw += 180; - } - } - - if (attachedTime > 13000) { - if (world.rand.nextInt(300) == 0) { - player.attackEntityFrom(DAMAGE_SOURCE, 1F); - } - } - - if (itemStack.getItemDamage() >= getMaxDamage(itemStack) - 1) { - itemStack.damageItem(10, player); - - player.attackEntityFrom(DAMAGE_SOURCE, player.getMaxHealth() - 0.01F); - player.getFoodStats().setFoodLevel(1); - - Vec3d pos = player.getPositionVector(); - - player.world.newExplosion(player, pos.x, pos.y, pos.z, 10, false, false); - - UWorld.scheduleTask(w -> { - w.newExplosion(player, pos.x, pos.y, pos.z, 6, false, true); - }, 50); - } - - iplayer.getInventory().enforceDependency(this); - } - - @Override - public void onRemoved(IPlayer player, float needfulness) { - - float attachedTime = player.getInventory().getTicksAttached(this) / 100F; - - DifficultyInstance difficulty = player.getWorld().getDifficultyForLocation(player.getOrigin()); - float amount = (attachedTime * (1 + needfulness)) * (1 + difficulty.getClampedAdditionalDifficulty()); - - amount = Math.min(amount, player.getOwner().getMaxHealth()); - - player.getOwner().attackEntityFrom(DAMAGE_SOURCE, amount); - - if (attachedTime > 120) { - player.getOwner().knockBack(player.getOwner(), 1, 1, 1); - } - } - - @Override - public String getArmorTexture(ItemStack stack, Entity entity, EntityEquipmentSlot slot, String type) { - return "unicopia:textures/models/armor/alicorn_amulet.png"; - } - - @Override - public Multimap getItemAttributeModifiers(EntityEquipmentSlot equipmentSlot) { - Multimap multimap = HashMultimap.create();; - - if (equipmentSlot == armorType) { - UUID modifierId = ARMOR_MODIFIERS[equipmentSlot.getIndex()]; - - multimap.put(SharedMonsterAttributes.ARMOR.getName(), new AttributeModifier(modifierId, "Armor modifier", Integer.MAX_VALUE, 0)); - multimap.put(SharedMonsterAttributes.ARMOR_TOUGHNESS.getName(), new AttributeModifier(modifierId, "Armor toughness", 20, 0)); - multimap.put(SharedMonsterAttributes.ATTACK_DAMAGE.getName(), new AttributeModifier(modifierId, "Strength modifier", 50, 0)); - } - - return multimap; - } -} diff --git a/src/main/java/com/minelittlepony/unicopia/item/ItemAppleMultiType.java b/src/main/java/com/minelittlepony/unicopia/item/ItemAppleMultiType.java deleted file mode 100644 index 68797c04..00000000 --- a/src/main/java/com/minelittlepony/unicopia/item/ItemAppleMultiType.java +++ /dev/null @@ -1,81 +0,0 @@ -package com.minelittlepony.unicopia.item; - -import com.minelittlepony.unicopia.forgebullshit.IMultiItem; - -import net.minecraft.creativetab.CreativeTabs; -import net.minecraft.entity.item.EntityItem; -import net.minecraft.item.ItemStack; -import net.minecraft.util.NonNullList; - -public class ItemAppleMultiType extends AppleItem implements IMultiItem { - - private String[] subTypes = new String[0]; - - private String[] variants = subTypes; - - public ItemAppleMultiType(String domain, String name) { - super(domain, name); - } - - public ItemAppleMultiType setSubTypes(String... types) { - setHasSubtypes(types.length > 0); - setMaxDamage(0); - - subTypes = types; - variants = new String[types.length]; - - setTranslationKey(variants[0] = types[0]); - - for (int i = 1; i < variants.length; i++) { - variants[i] = variants[0] + "_" + types[i % types.length]; - } - return this; - } - - @Override - public String[] getVariants() { - return variants; - } - - protected String[] getSubTypes() { - return subTypes; - } - - @Override - public void getSubItems(CreativeTabs tab, NonNullList items) { - if (isInCreativeTab(tab)) { - items.add(new ItemStack(this, 1, 0)); - - for (int i = 1; i < getSubTypes().length; i++) { - items.add(new ItemStack(this, 1, i)); - } - } - } - - @Override - public int getMetadata(ItemStack stack) { - if (getHasSubtypes()) { - return super.getMetadata(stack) % getSubTypes().length; - } - - return super.getMetadata(stack); - } - - @Override - public boolean onEntityItemUpdate(EntityItem item) { - return false; - } - - @Override - public String getTranslationKey(ItemStack stack) { - if (getHasSubtypes()) { - int meta = Math.max(0, stack.getMetadata() % getSubTypes().length); - - if (meta > 0) { - return super.getTranslationKey(stack) + "." + getSubTypes()[meta]; - } - } - - return super.getTranslationKey(stack); - } -} diff --git a/src/main/java/com/minelittlepony/unicopia/item/ItemCereal.java b/src/main/java/com/minelittlepony/unicopia/item/ItemCereal.java deleted file mode 100644 index 1208051a..00000000 --- a/src/main/java/com/minelittlepony/unicopia/item/ItemCereal.java +++ /dev/null @@ -1,44 +0,0 @@ -package com.minelittlepony.unicopia.item; - -import com.minelittlepony.unicopia.SpeciesList; - -import net.minecraft.entity.LivingEntity; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.init.Items; -import net.minecraft.item.ItemFood; -import net.minecraft.item.ItemStack; -import net.minecraft.world.World; - -public class ItemCereal extends ItemFood { - - private int sugarAmount; - - public ItemCereal(String domain, String name, int amount, float saturation) { - super(amount, saturation, false); - - setTranslationKey(name); - setRegistryName(domain, name); - setMaxStackSize(1); - setContainerItem(Items.BOWL); - } - - public ItemStack onItemUseFinish(ItemStack stack, World worldIn, LivingEntity entityLiving) { - super.onItemUseFinish(stack, worldIn, entityLiving); - - return getContainerItem(stack); - } - - @Override - protected void onFoodEaten(ItemStack stack, World worldIn, PlayerEntity player) { - super.onFoodEaten(stack, worldIn, player); - - if (sugarAmount != 0) { - SpeciesList.instance().getPlayer(player).addEnergy(sugarAmount); - } - } - - public ItemCereal setSugarAmount(int sugar) { - sugarAmount = sugar; - return this; - } -} diff --git a/src/main/java/com/minelittlepony/unicopia/item/ItemMagicStaff.java b/src/main/java/com/minelittlepony/unicopia/item/ItemMagicStaff.java deleted file mode 100644 index d90c8861..00000000 --- a/src/main/java/com/minelittlepony/unicopia/item/ItemMagicStaff.java +++ /dev/null @@ -1,156 +0,0 @@ -package com.minelittlepony.unicopia.item; - -import java.util.List; - -import javax.annotation.Nonnull; -import javax.annotation.Nullable; - -import com.minelittlepony.unicopia.EquinePredicates; -import com.minelittlepony.unicopia.SpeciesList; -import com.minelittlepony.unicopia.entity.capabilities.IPlayer; -import com.minelittlepony.unicopia.projectile.ITossableItem; -import com.minelittlepony.unicopia.spell.CasterUtils; -import com.minelittlepony.unicopia.spell.IAligned; -import com.minelittlepony.unicopia.spell.ICaster; -import com.minelittlepony.unicopia.spell.ITossedEffect; -import com.minelittlepony.unicopia.spell.SpellAffinity; -import com.minelittlepony.util.lang.ClientLocale; - -import net.minecraft.block.state.BlockState; -import net.minecraft.client.util.ITooltipFlag; -import net.minecraft.entity.Entity; -import net.minecraft.entity.LivingEntity; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.init.SoundEvents; -import net.minecraft.item.ItemStack; -import net.minecraft.util.ActionResult; -import net.minecraft.util.DamageSource; -import net.minecraft.util.EnumActionResult; -import net.minecraft.util.EnumHand; -import net.minecraft.util.EnumParticleTypes; -import net.minecraft.util.SoundCategory; -import net.minecraft.util.math.BlockPos; -import net.minecraft.util.math.Vec3d; -import net.minecraft.world.World; - -public class ItemMagicStaff extends ItemStaff implements IAligned, ITossableItem { - - @Nonnull - private final ITossedEffect effect; - - public ItemMagicStaff(String domain, String name, @Nonnull ITossedEffect effect) { - super(domain, name); - - this.effect = effect; - setMaxDamage(500); - } - - @Override - public void addInformation(ItemStack stack, @Nullable World worldIn, List tooltip, ITooltipFlag flagIn) { - SpellAffinity affinity = getAffinity(); - tooltip.add(affinity.getColourCode() + ClientLocale.format(affinity.getUnlocalizedName())); - } - - @Override - public TypedActionResult onItemRightClick(World world, PlayerEntity player, EnumHand hand) { - if (EquinePredicates.MAGI.test(player) && hand == EnumHand.MAIN_HAND) { - ItemStack itemstack = player.getStackInHand(hand); - - player.setActiveHand(hand); - - return new TypedActionResult(EnumActionResult.SUCCESS, itemstack); - } - - return super.onItemRightClick(world, player, hand); - } - - @Override - public void onPlayerStoppedUsing(ItemStack itemstack, World world, LivingEntity entity, int timeLeft) { - if (EquinePredicates.MAGI.test(entity) && entity instanceof PlayerEntity) { - - int i = getMaxItemUseDuration(itemstack) - timeLeft; - - if (i > 10) { - if (canBeThrown(itemstack)) { - toss(world, itemstack, (PlayerEntity)entity); - } - } - } - } - - @Override - protected boolean castContainedEffect(ItemStack stack, LivingEntity target, LivingEntity attacker) { - if (attacker.isSneaking()) { - stack.damageItem(50, attacker); - - CasterUtils.toCaster(attacker).ifPresent(c -> c.subtractEnergyCost(4)); - - onImpact( - CasterUtils.near(target), - target.getPosition(), - target.getEntityWorld().getBlockState(target.getPosition()) - ); - - return true; - } - - return false; - } - - public void onUpdate(ItemStack stack, World world, Entity entity, int itemSlot, boolean isSelected) { - - if (entity instanceof LivingEntity) { - LivingEntity living = (LivingEntity)entity; - - if (living.getActiveItemStack().getItem() == this) { - Vec3d eyes = entity.getPositionEyes(1); - - float i = getMaxItemUseDuration(stack) - living.getItemInUseCount(); - - world.spawnParticle(i > 150 ? EnumParticleTypes.SMOKE_LARGE : EnumParticleTypes.CLOUD, eyes.x, eyes.y, eyes.z, - (world.rand.nextGaussian() - 0.5) / 10, - (world.rand.nextGaussian() - 0.5) / 10, - (world.rand.nextGaussian() - 0.5) / 10 - ); - world.playSound(null, entity.getPosition(), SoundEvents.ENTITY_GUARDIAN_ATTACK, SoundCategory.PLAYERS, 1, i / 20); - - if (i > 200) { - living.resetActiveHand(); - living.attackEntityFrom(DamageSource.MAGIC, 1200); - onImpact( - CasterUtils.toCaster(entity).orElseGet(() -> CasterUtils.near(entity)), - entity.getPosition(), - entity.getEntityWorld().getBlockState(entity.getPosition()) - ); - } - } - } - - } - - @Override - public int getMaxItemUseDuration(ItemStack stack) { - return 72000; - } - - @Override - public void toss(World world, ItemStack stack, PlayerEntity player) { - IPlayer iplayer = SpeciesList.instance().getPlayer(player); - - iplayer.subtractEnergyCost(4); - effect.toss(iplayer); - - stack.damageItem(1, player); - } - - @Override - public void onImpact(ICaster caster, BlockPos pos, BlockState state) { - effect.onImpact(caster, pos, state); - } - - @Override - public SpellAffinity getAffinity() { - return effect.getAffinity(); - } - -} diff --git a/src/main/java/com/minelittlepony/unicopia/item/ItemOfHolding.java b/src/main/java/com/minelittlepony/unicopia/item/ItemOfHolding.java deleted file mode 100644 index 143d903b..00000000 --- a/src/main/java/com/minelittlepony/unicopia/item/ItemOfHolding.java +++ /dev/null @@ -1,174 +0,0 @@ -package com.minelittlepony.unicopia.item; - -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import javax.annotation.Nullable; - -import com.minelittlepony.unicopia.EquinePredicates; -import com.minelittlepony.unicopia.UClient; -import com.minelittlepony.unicopia.inventory.gui.ContainerOfHolding; -import com.minelittlepony.unicopia.inventory.gui.InventoryOfHolding; -import com.minelittlepony.unicopia.magic.items.IMagicalItem; -import com.minelittlepony.unicopia.spell.SpellAffinity; -import com.minelittlepony.util.VecHelper; - -import net.minecraft.client.util.ITooltipFlag; - -import net.minecraft.creativetab.CreativeTabs; -import net.minecraft.entity.Entity; -import net.minecraft.entity.item.EntityItem; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.entity.player.InventoryPlayer; -import net.minecraft.init.SoundEvents; -import net.minecraft.inventory.Container; -import net.minecraft.inventory.IInventory; -import net.minecraft.item.Item; -import net.minecraft.item.ItemStack; -import net.minecraft.tileentity.TileEntity; -import net.minecraft.util.ActionResult; -import net.minecraft.util.EnumActionResult; -import net.minecraft.util.EnumHand; -import net.minecraft.util.math.Box; -import net.minecraft.util.math.BlockPos; -import net.minecraft.util.math.RayTraceResult; -import net.minecraft.util.text.ITextComponent; -import net.minecraft.util.text.TextComponentString; -import net.minecraft.util.text.TextComponentTranslation; -import net.minecraft.world.IInteractionObject; -import net.minecraft.world.World; -import net.minecraftforge.fml.relauncher.Side; -import net.minecraftforge.fml.relauncher.SideOnly; - -public class ItemOfHolding extends Item implements IMagicalItem { - - public ItemOfHolding(String domain, String name) { - setCreativeTab(CreativeTabs.TRANSPORTATION); - setTranslationKey(name); - setRegistryName(domain, name); - setMaxStackSize(1); - } - - @SideOnly(Side.CLIENT) - @Override - public void addInformation(ItemStack stack, @Nullable World worldIn, List tooltip, ITooltipFlag flagIn) { - super.addInformation(stack, worldIn, tooltip, flagIn); - - Map counts = new HashMap<>(); - - InventoryOfHolding.iterateContents(stack, (i, itemstack) -> { - String name = itemstack.getDisplayName(); - - counts.put(name, counts.getOrDefault(name, 0) + itemstack.getCount()); - return true; - }); - - for (String name : counts.keySet()) { - tooltip.add(String.format("%s x%d", name, counts.get(name))); - } - } - - @Override - public TypedActionResult onItemRightClick(World world, PlayerEntity player, EnumHand hand) { - - if (!EquinePredicates.MAGI.test(player)) { - return super.onItemRightClick(world, player, hand); - } - - ItemStack stack = player.getStackInHand(hand); - - if (player.isSneaking()) { - RayTraceResult hit = VecHelper.getObjectMouseOver(player, 5, 0); - - if (hit != null) { - if (hit.typeOfHit == RayTraceResult.Type.BLOCK) { - BlockPos pos = hit.getBlockPos(); - - TileEntity tile = world.getTileEntity(pos); - - if (tile instanceof IInventory) { - InventoryOfHolding inventory = InventoryOfHolding.getInventoryFromStack(stack); - - inventory.addBlockEntity(world, pos, (TileEntity & IInventory)tile); - inventory.writeTostack(stack); - inventory.closeInventory(player); - - return new TypedActionResult<>(EnumActionResult.SUCCESS, stack); - } - - Box box = new Box(pos.offset(hit.sideHit)).grow(0.5); - - List itemsAround = world.getEntitiesInAABBexcluding(player, box, EquinePredicates.ITEMS); - - if (itemsAround.size() > 0) { - InventoryOfHolding inventory = InventoryOfHolding.getInventoryFromStack(stack); - - inventory.addItem((EntityItem)itemsAround.get(0)); - inventory.writeTostack(stack); - inventory.closeInventory(player); - - return new TypedActionResult<>(EnumActionResult.SUCCESS, stack); - } - } - } - - return new TypedActionResult<>(EnumActionResult.FAIL, stack); - } - - UClient.instance().displayGuiToPlayer(player, new Inventory(stack)); - - player.playSound(SoundEvents.BLOCK_ENDERCHEST_OPEN, 0.5F, 1); - - return new TypedActionResult<>(EnumActionResult.SUCCESS, stack); - } - - @Override - public SpellAffinity getAffinity() { - return SpellAffinity.NEUTRAL; - } - - @Override - public boolean hasInnerSpace() { - return true; - } - - public class Inventory implements IInteractionObject { - - private String customname = null; - - Inventory(ItemStack stack) { - if (stack.hasDisplayName()) { - customname = stack.getDisplayName(); - } - } - - @Override - public String getName() { - return "unicopi.gui.title.itemofholding"; - } - - @Override - public boolean hasCustomName() { - return customname != null; - } - - @Override - public ITextComponent getDisplayName() { - if (hasCustomName()) { - return new TextComponentString(customname); - } - return new TextComponentTranslation(getName()); - } - - @Override - public Container createContainer(InventoryPlayer playerInventory, PlayerEntity player) { - return new ContainerOfHolding(player); - } - - @Override - public String getGuiID() { - return "unicopia:itemofholding"; - } - } -} diff --git a/src/main/java/com/minelittlepony/unicopia/item/ItemStaff.java b/src/main/java/com/minelittlepony/unicopia/item/ItemStaff.java deleted file mode 100644 index 2a5d176b..00000000 --- a/src/main/java/com/minelittlepony/unicopia/item/ItemStaff.java +++ /dev/null @@ -1,108 +0,0 @@ -package com.minelittlepony.unicopia.item; - -import java.util.List; -import java.util.UUID; - -import javax.annotation.Nullable; - -import com.google.common.collect.HashMultimap; -import com.google.common.collect.Multimap; -import com.minelittlepony.unicopia.EquinePredicates; -import com.minelittlepony.util.lang.ClientLocale; - -import net.minecraft.block.Block; -import net.minecraft.client.util.ITooltipFlag; -import net.minecraft.entity.Entity; -import net.minecraft.entity.LivingEntity; -import net.minecraft.entity.SharedMonsterAttributes; -import net.minecraft.entity.ai.attributes.AttributeModifier; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.init.Blocks; -import net.minecraft.init.SoundEvents; -import net.minecraft.inventory.EntityEquipmentSlot; -import net.minecraft.item.EnumAction; -import net.minecraft.item.ItemStack; -import net.minecraft.item.ItemSword; -import net.minecraft.util.EnumParticleTypes; -import net.minecraft.util.math.MathHelper; -import net.minecraft.world.World; - -public class ItemStaff extends ItemSword { - - protected static final UUID ATTACK_REACH_MODIFIER = UUID.fromString("FA235E1C-4280-A865-B01B-CBAE9985ACA3"); - - public ItemStaff(String domain, String name) { - super(ToolMaterial.WOOD); - - setTranslationKey(name); - setRegistryName(domain, name); - - setMaxStackSize(1); - } - - @Override - public boolean onLeftClickEntity(ItemStack stack, PlayerEntity player, Entity target) { - World w = player.getEntityWorld(); - - for (int i = 0; i < 130; i++) { - w.spawnParticle(EnumParticleTypes.BLOCK_CRACK, - target.posX + (target.world.rand.nextFloat() - 0.5F) * (target.width + 1), - (target.posY + target.height/2) + (target.world.rand.nextFloat() - 0.5F) * target.height, - target.posZ + (target.world.rand.nextFloat() - 0.5F) * (target.width + 1), - 0, 0, 0, - Block.getStateId(Blocks.LOG.getDefaultState()) - ); - } - - return false; - } - - @Override - public void addInformation(ItemStack stack, @Nullable World worldIn, List tooltip, ITooltipFlag flagIn) { - tooltip.add(ClientLocale.format(getTranslationKey(stack) + ".tagline")); - } - - @Override - public boolean hitEntity(ItemStack stack, LivingEntity target, LivingEntity attacker) { - super.hitEntity(stack, target, attacker); - - if (EquinePredicates.MAGI.test(attacker)) { - return castContainedEffect(stack, target, attacker); - } - - return false; - } - - protected boolean castContainedEffect(ItemStack stack, LivingEntity target, LivingEntity attacker) { - target.getEntityWorld().playSound(null, target.getPosition(), SoundEvents.ENTITY_PLAYER_ATTACK_CRIT, attacker.getSoundCategory(), 1, 1); - - target.knockBack(attacker, 2, - MathHelper.sin(attacker.rotationYaw * 0.017453292F), - -MathHelper.cos(attacker.rotationYaw * 0.017453292F) - ); - - return true; - } - - @Override - public boolean isFull3D() { - return true; - } - - @Override - public EnumAction getItemUseAction(ItemStack stack) { - return EnumAction.BOW; - } - - @Override - public Multimap getItemAttributeModifiers(EntityEquipmentSlot slot) { - Multimap multimap = HashMultimap.create(); - - if (slot == EntityEquipmentSlot.MAINHAND) { - multimap.put(SharedMonsterAttributes.ATTACK_DAMAGE.getName(), new AttributeModifier(ATTACK_DAMAGE_MODIFIER, "Weapon modifier", getAttackDamage(), 0)); - multimap.put(PlayerEntity.REACH_DISTANCE.getName(), new AttributeModifier(ATTACK_REACH_MODIFIER, "Weapon modifier", 3, 0)); - } - - return multimap; - } -} diff --git a/src/main/java/com/minelittlepony/unicopia/item/ItemZapApple.java b/src/main/java/com/minelittlepony/unicopia/item/ItemZapApple.java deleted file mode 100644 index 607a1b0a..00000000 --- a/src/main/java/com/minelittlepony/unicopia/item/ItemZapApple.java +++ /dev/null @@ -1,84 +0,0 @@ -package com.minelittlepony.unicopia.item; - - -import com.minelittlepony.unicopia.item.consumables.Toxicity; -import com.minelittlepony.util.MagicalDamageSource; -import com.minelittlepony.util.VecHelper; - -import net.minecraft.entity.Entity; -import net.minecraft.entity.LightningEntity; -import net.minecraft.item.ItemStack; -import net.minecraft.util.ActionResult; -import net.minecraft.util.DefaultedList; -import net.minecraft.world.World; - -public class ItemZapApple extends ItemAppleMultiType { - - public ItemZapApple(String domain, String name) { - super(domain, name); - setAlwaysEdible(); - } - - @Override - public TypedActionResult onItemRightClick(World world, PlayerEntity player, EnumHand hand) { - RayTraceResult mop = VecHelper.getObjectMouseOver(player, 5, 0); - - if (mop != null && mop.typeOfHit == RayTraceResult.Type.ENTITY) { - ItemStack stack = player.getStackInHand(hand); - - if (canFeedTo(stack, mop.entityHit)) { - return onFedTo(stack, player, mop.entityHit); - } - } - - return super.onItemRightClick(world, player, hand); - } - - @Override - protected void onFoodEaten(ItemStack stack, World w, PlayerEntity player) { - super.onFoodEaten(stack, w, player); - - player.attackEntityFrom(MagicalDamageSource.create("zap"), 120); - - w.addWeatherEffect(new EntityLightningBolt(w, player.posX, player.posY, player.posZ, false)); - } - - public boolean canFeedTo(ItemStack stack, Entity e) { - return e instanceof EntityVillager - || e instanceof EntityCreeper - || e instanceof EntityPig; - } - - public TypedActionResult onFedTo(ItemStack stack, PlayerEntity player, Entity e) { - e.onStruckByLightning(new LightningEntity(e.world, e.posX, e.posY, e.posZ, false)); - - if (!player.capabilities.isCreativeMode) { - stack.shrink(1); - } - - return new TypedActionResult(ActionResult.SUCCESS, stack); - } - - @Override - public void getSubItems(CreativeTabs tab, DefaultedList items) { - if (isInCreativeTab(tab)) { - items.add(new ItemStack(this, 1, 0)); - } - } - - @Override - public Toxicity getToxicityLevel(ItemStack stack) { - return stack.getMetadata() == 0 ? Toxicity.SEVERE : Toxicity.SAFE; - } - - @Override - public EnumRarity getRarity(ItemStack stack) { - int meta = stack.getMetadata(); - - if (meta == 0) { - return EnumRarity.EPIC; - } - - return EnumRarity.RARE; - } -} diff --git a/src/main/java/com/minelittlepony/unicopia/item/MagicGemItem.java b/src/main/java/com/minelittlepony/unicopia/item/MagicGemItem.java index 4f060c2d..4cd4e40d 100644 --- a/src/main/java/com/minelittlepony/unicopia/item/MagicGemItem.java +++ b/src/main/java/com/minelittlepony/unicopia/item/MagicGemItem.java @@ -11,7 +11,7 @@ import com.minelittlepony.unicopia.magic.IDispenceable; import com.minelittlepony.unicopia.magic.IMagicEffect; import com.minelittlepony.unicopia.magic.IUseable; import com.minelittlepony.unicopia.magic.items.ICastable; -import com.minelittlepony.unicopia.magic.spells.SpellCastResult; +import com.minelittlepony.unicopia.magic.spells.CastResult; import com.minelittlepony.unicopia.magic.spells.SpellRegistry; import com.minelittlepony.util.VecHelper; @@ -50,7 +50,7 @@ public class MagicGemItem extends Item implements ICastable { } @Override - public SpellCastResult onDispenseSpell(BlockPointer source, ItemStack stack, IDispenceable effect) { + public CastResult onDispenseSpell(BlockPointer source, ItemStack stack, IDispenceable effect) { Direction facing = source.getBlockState().get(DispenserBlock.FACING); BlockPos pos = source.getBlockPos().offset(facing); @@ -58,12 +58,12 @@ public class MagicGemItem extends Item implements ICastable { } @Override - public SpellCastResult onCastSpell(ItemUsageContext context, IMagicEffect effect) { + public CastResult onCastSpell(ItemUsageContext context, IMagicEffect effect) { if (effect instanceof IUseable) { return ((IUseable)effect).onUse(context, getAffinity(context.getStack())); } - return SpellCastResult.PLACE; + return CastResult.PLACE; } @Override @@ -89,17 +89,17 @@ public class MagicGemItem extends Item implements ICastable { return ActionResult.FAIL; } - SpellCastResult result = onCastSpell(context, effect); + CastResult result = onCastSpell(context, effect); if (!context.getWorld().isClient) { pos = pos.offset(context.getSide()); - if (result == SpellCastResult.PLACE) { + if (result == CastResult.PLACE) { castContainedSpell(context.getWorld(), pos, stack, effect).setOwner(player); } } - if (result != SpellCastResult.NONE) { + if (result != CastResult.NONE) { if (!player.isCreative()) { stack.decrement(1); } @@ -126,10 +126,10 @@ public class MagicGemItem extends Item implements ICastable { IUseable effect = SpellRegistry.instance().getUseActionFrom(stack); if (effect != null) { - SpellCastResult result = effect.onUse(stack, getAffinity(stack), player, world, VecHelper.getLookedAtEntity(player, 5)); + CastResult result = effect.onUse(stack, getAffinity(stack), player, world, VecHelper.getLookedAtEntity(player, 5)); - if (result != SpellCastResult.NONE) { - if (result == SpellCastResult.PLACE && !player.isCreative()) { + if (result != CastResult.NONE) { + if (result == CastResult.PLACE && !player.isCreative()) { stack.decrement(1); } diff --git a/src/main/java/com/minelittlepony/unicopia/item/MossItem.java b/src/main/java/com/minelittlepony/unicopia/item/MossItem.java index 26d02a67..900e47cb 100644 --- a/src/main/java/com/minelittlepony/unicopia/item/MossItem.java +++ b/src/main/java/com/minelittlepony/unicopia/item/MossItem.java @@ -3,7 +3,7 @@ package com.minelittlepony.unicopia.item; import javax.annotation.Nullable; import com.minelittlepony.unicopia.SpeciesList; -import com.minelittlepony.unicopia.item.consumables.ItemEdible; +import com.minelittlepony.unicopia.item.consumables.EdibleItem; import com.minelittlepony.unicopia.item.consumables.Toxicity; import com.minelittlepony.util.collection.ReversableStateMapList; import net.minecraft.block.Block; @@ -17,7 +17,7 @@ import net.minecraft.sound.SoundEvents; import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; -public class MossItem extends ItemEdible { +public class MossItem extends EdibleItem { public static final ReversableStateMapList AFFECTED = new ReversableStateMapList(); diff --git a/src/main/java/com/minelittlepony/unicopia/item/RottenAppleItem.java b/src/main/java/com/minelittlepony/unicopia/item/RottenAppleItem.java index 6205bcde..19ffd0cd 100644 --- a/src/main/java/com/minelittlepony/unicopia/item/RottenAppleItem.java +++ b/src/main/java/com/minelittlepony/unicopia/item/RottenAppleItem.java @@ -1,8 +1,10 @@ package com.minelittlepony.unicopia.item; +import com.minelittlepony.unicopia.ducks.IItemEntity; + import net.fabricmc.fabric.api.registry.FuelRegistry; -import net.minecraft.entity.ItemEntity; import net.minecraft.item.FoodComponent; +import net.minecraft.util.ActionResult; public class RottenAppleItem extends AppleItem { @@ -12,7 +14,7 @@ public class RottenAppleItem extends AppleItem { } @Override - public boolean onEntityItemUpdate(ItemEntity item) { - return false; + public ActionResult onGroundTick(IItemEntity item) { + return ActionResult.PASS; } } \ No newline at end of file diff --git a/src/main/java/com/minelittlepony/unicopia/item/RottenTomatoItem.java b/src/main/java/com/minelittlepony/unicopia/item/RottenTomatoItem.java index 89ec0fef..2e4c70ab 100644 --- a/src/main/java/com/minelittlepony/unicopia/item/RottenTomatoItem.java +++ b/src/main/java/com/minelittlepony/unicopia/item/RottenTomatoItem.java @@ -10,7 +10,6 @@ import net.minecraft.entity.LivingEntity; import net.minecraft.entity.effect.StatusEffectInstance; import net.minecraft.entity.effect.StatusEffects; import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.item.FoodComponent; import net.minecraft.item.ItemStack; import net.minecraft.util.ActionResult; import net.minecraft.util.Hand; @@ -20,8 +19,8 @@ import net.minecraft.world.World; public class RottenTomatoItem extends TomatoItem implements ITossableItem { - public RottenTomatoItem(FoodComponent components) { - super(components); + public RottenTomatoItem(int hunger, float saturation) { + super(hunger, saturation); setDispenseable(); } diff --git a/src/main/java/com/minelittlepony/unicopia/item/ItemSpear.java b/src/main/java/com/minelittlepony/unicopia/item/SpearItem.java similarity index 62% rename from src/main/java/com/minelittlepony/unicopia/item/ItemSpear.java rename to src/main/java/com/minelittlepony/unicopia/item/SpearItem.java index c1035661..f668a232 100644 --- a/src/main/java/com/minelittlepony/unicopia/item/ItemSpear.java +++ b/src/main/java/com/minelittlepony/unicopia/item/SpearItem.java @@ -2,71 +2,66 @@ package com.minelittlepony.unicopia.item; import javax.annotation.Nullable; -import com.minelittlepony.unicopia.entity.EntitySpear; +import com.minelittlepony.unicopia.entity.SpearEntity; import com.minelittlepony.unicopia.magic.ICaster; import com.minelittlepony.unicopia.projectile.IAdvancedProjectile; import com.minelittlepony.unicopia.projectile.ITossableItem; import net.minecraft.block.BlockState; +import net.minecraft.entity.EquipmentSlot; import net.minecraft.entity.LivingEntity; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.util.ActionResult; +import net.minecraft.util.Hand; +import net.minecraft.util.TypedActionResult; +import net.minecraft.util.UseAction; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.Position; import net.minecraft.world.World; -public class ItemSpear extends Item implements ITossableItem { +public class SpearItem extends Item implements ITossableItem { - public ItemSpear(String domain, String name) { - setFull3D(); - setTranslationKey(name); - setRegistryName(domain, name); - setMaxStackSize(1); - setMaxDamage(500); + public SpearItem(Settings settings) { + super(settings); } @Override - public EnumAction getItemUseAction(ItemStack stack) { - return EnumAction.BOW; + public UseAction getUseAction(ItemStack stack) { + return UseAction.BOW; } @Override - public boolean isFull3D() { - return true; - } - - @Override - public int getMaxItemUseDuration(ItemStack stack) { + public int getMaxUseTime(ItemStack stack) { return 440; } @Override - public TypedActionResult onItemRightClick(World world, PlayerEntity player, EnumHand hand) { + public TypedActionResult use(World world, PlayerEntity player, Hand hand) { if (!world.isClient) { ItemStack itemstack = player.getStackInHand(hand); if (canBeThrown(itemstack)) { - player.setActiveHand(hand); + player.swingHand(hand); - return new TypedActionResult(EnumActionResult.SUCCESS, itemstack); + return new TypedActionResult<>(ActionResult.SUCCESS, itemstack); } } - return super.onItemRightClick(world, player, hand); + return super.use(world, player, hand); } @Override - public void onPlayerStoppedUsing(ItemStack itemstack, World world, LivingEntity entity, int timeLeft) { + public void onStoppedUsing(ItemStack itemstack, World world, LivingEntity entity, int timeLeft) { if (entity instanceof PlayerEntity) { - int i = getMaxItemUseDuration(itemstack) - timeLeft; + int i = getMaxUseTime(itemstack) - timeLeft; if (i > 10) { if (canBeThrown(itemstack)) { - itemstack.damageItem(1, entity); + itemstack.damage(1, entity, p -> p.sendEquipmentBreakStatus(EquipmentSlot.MAINHAND)); toss(world, itemstack, (PlayerEntity)entity); } } @@ -90,7 +85,7 @@ public class ItemSpear extends Item implements ITossableItem { @Nullable @Override public IAdvancedProjectile createProjectile(World world, PlayerEntity player) { - return new EntitySpear(world, player); + return new SpearEntity(world, player); } @Nullable diff --git a/src/main/java/com/minelittlepony/unicopia/item/StaffItem.java b/src/main/java/com/minelittlepony/unicopia/item/StaffItem.java new file mode 100644 index 00000000..424ec840 --- /dev/null +++ b/src/main/java/com/minelittlepony/unicopia/item/StaffItem.java @@ -0,0 +1,99 @@ +package com.minelittlepony.unicopia.item; + +import java.util.List; +import java.util.UUID; + +import com.google.common.collect.HashMultimap; +import com.google.common.collect.Multimap; +import com.minelittlepony.unicopia.EquinePredicates; +import net.minecraft.block.Blocks; +import net.minecraft.client.item.TooltipContext; +import net.minecraft.entity.EntityDimensions; +import net.minecraft.entity.EquipmentSlot; +import net.minecraft.entity.LivingEntity; +import net.minecraft.entity.attribute.EntityAttributeModifier; +import net.minecraft.entity.attribute.EntityAttributes; +import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.item.ItemStack; +import net.minecraft.item.SwordItem; +import net.minecraft.item.ToolMaterials; +import net.minecraft.particle.BlockStateParticleEffect; +import net.minecraft.particle.ParticleTypes; +import net.minecraft.sound.SoundEvents; +import net.minecraft.text.Text; +import net.minecraft.text.TranslatableText; +import net.minecraft.util.Hand; +import net.minecraft.util.UseAction; +import net.minecraft.util.math.MathHelper; +import net.minecraft.world.World; + +public class StaffItem extends SwordItem { + + protected static final UUID ATTACK_REACH_MODIFIER = UUID.fromString("FA235E1C-4280-A865-B01B-CBAE9985ACA3"); + + public StaffItem(Settings settings) { + super(ToolMaterials.WOOD, 2, 4, settings); + } + + @Override + public boolean useOnEntity(ItemStack stack, PlayerEntity player, LivingEntity target, Hand hand) { + World w = player.getEntityWorld(); + + EntityDimensions dims = target.getDimensions(target.getPose()); + + for (int i = 0; i < 130; i++) { + w.addParticle(new BlockStateParticleEffect(ParticleTypes.BLOCK, Blocks.OAK_LOG.getDefaultState()), + target.x + (target.world.random.nextFloat() - 0.5F) * (dims.width + 1), + (target.y + dims.height / 2) + (target.world.random.nextFloat() - 0.5F) * dims.height, + target.z + (target.world.random.nextFloat() - 0.5F) * (dims.width + 1), + 0, 0, 0 + ); + } + + return false; + } + + @Override + public void appendTooltip(ItemStack stack, World world, List tooltip, TooltipContext context) { + tooltip.add(new TranslatableText(getTranslationKey(stack) + ".tagline")); + } + + @Override + public boolean postHit(ItemStack stack, LivingEntity entity, LivingEntity attacker) { + super.postHit(stack, entity, attacker); + + if (EquinePredicates.MAGI.test(entity)) { + return castContainedEffect(stack, entity, attacker); + } + + return false; + } + + protected boolean castContainedEffect(ItemStack stack, LivingEntity target, LivingEntity attacker) { + target.getEntityWorld().playSound(null, target.getBlockPos(), SoundEvents.ENTITY_PLAYER_ATTACK_CRIT, attacker.getSoundCategory(), 1, 1); + + target.takeKnockback(attacker, 2, + MathHelper.sin(attacker.yaw * 0.017453292F), + -MathHelper.cos(attacker.yaw * 0.017453292F) + ); + + return true; + } + + @Override + public UseAction getUseAction(ItemStack stack) { + return UseAction.BOW; + } + + @Override + public Multimap getModifiers(EquipmentSlot slot) { + Multimap multimap = HashMultimap.create(); + + if (slot == EquipmentSlot.MAINHAND) { + multimap.put(EntityAttributes.ATTACK_DAMAGE.getId(), new EntityAttributeModifier(ATTACK_DAMAGE_MODIFIER_UUID, "Weapon modifier", getAttackDamage(), EntityAttributeModifier.Operation.ADDITION)); + //multimap.put(PlayerEntity.REACH_DISTANCE.getId(), new EntityAttributeModifier(ATTACK_REACH_MODIFIER, "Weapon modifier", 3, EntityAttributeModifier.Operation.ADDITION)); + } + + return multimap; + } +} diff --git a/src/main/java/com/minelittlepony/unicopia/item/SugaryItem.java b/src/main/java/com/minelittlepony/unicopia/item/SugaryItem.java new file mode 100644 index 00000000..76f9a05c --- /dev/null +++ b/src/main/java/com/minelittlepony/unicopia/item/SugaryItem.java @@ -0,0 +1,28 @@ +package com.minelittlepony.unicopia.item; + +import com.minelittlepony.unicopia.SpeciesList; + +import net.minecraft.entity.LivingEntity; +import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.world.World; + +public class SugaryItem extends Item { + + private final int sugarAmount; + + public SugaryItem(Settings settings, int sugar) { + super(settings); + sugarAmount = sugar; + } + + @Override + public ItemStack finishUsing(ItemStack stack, World world, LivingEntity entity) { + if (sugarAmount != 0 && entity instanceof PlayerEntity) { + SpeciesList.instance().getPlayer((PlayerEntity)entity).addEnergy(sugarAmount); + } + + return super.finishUsing(stack, world, entity); + } +} diff --git a/src/main/java/com/minelittlepony/unicopia/item/TomatoItem.java b/src/main/java/com/minelittlepony/unicopia/item/TomatoItem.java index 1844c83c..3d463bef 100644 --- a/src/main/java/com/minelittlepony/unicopia/item/TomatoItem.java +++ b/src/main/java/com/minelittlepony/unicopia/item/TomatoItem.java @@ -4,13 +4,20 @@ import net.minecraft.entity.LivingEntity; import net.minecraft.entity.effect.StatusEffects; import net.minecraft.item.FoodComponent; import net.minecraft.item.Item; +import net.minecraft.item.ItemGroup; import net.minecraft.item.ItemStack; import net.minecraft.world.World; public class TomatoItem extends Item { - public TomatoItem(FoodComponent components) { - super(new Settings().food(components)); + public TomatoItem(int hunger, float saturation) { + super(new Settings() + .group(ItemGroup.FOOD) + .food(new FoodComponent.Builder() + .hunger(hunger) + .saturationModifier(saturation) + .build()) + ); } @Override diff --git a/src/main/java/com/minelittlepony/unicopia/item/ZapAppleItem.java b/src/main/java/com/minelittlepony/unicopia/item/ZapAppleItem.java new file mode 100644 index 00000000..1eba0636 --- /dev/null +++ b/src/main/java/com/minelittlepony/unicopia/item/ZapAppleItem.java @@ -0,0 +1,135 @@ +package com.minelittlepony.unicopia.item; + + +import java.util.List; + +import com.google.common.collect.Lists; +import com.minelittlepony.unicopia.UItems; +import com.minelittlepony.unicopia.item.consumables.Toxicity; +import com.minelittlepony.util.MagicalDamageSource; +import com.minelittlepony.util.VecHelper; + +import net.minecraft.entity.Entity; +import net.minecraft.entity.LightningEntity; +import net.minecraft.entity.LivingEntity; +import net.minecraft.entity.mob.CreeperEntity; +import net.minecraft.entity.passive.PigEntity; +import net.minecraft.entity.passive.VillagerEntity; +import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.item.FoodComponent; +import net.minecraft.item.Item; +import net.minecraft.item.ItemGroup; +import net.minecraft.item.ItemStack; +import net.minecraft.item.Items; +import net.minecraft.server.world.ServerWorld; +import net.minecraft.util.ActionResult; +import net.minecraft.util.DefaultedList; +import net.minecraft.util.Hand; +import net.minecraft.util.Identifier; +import net.minecraft.util.Rarity; +import net.minecraft.util.TypedActionResult; +import net.minecraft.util.hit.EntityHitResult; +import net.minecraft.util.hit.HitResult; +import net.minecraft.util.registry.Registry; +import net.minecraft.world.World; + +public class ZapAppleItem extends AppleItem { + + private static final List ALIASABLE_ITEMS = Lists.newArrayList( + UItems.red_apple, + UItems.green_apple, + UItems.sweet_apple, + UItems.sour_apple, + UItems.rotten_apple, + UItems.cooked_zap_apple + ); + + public ZapAppleItem() { + super(new FoodComponent.Builder() + .hunger(4) + .saturationModifier(0.3F) + .alwaysEdible().build()); + } + + @Override + public TypedActionResult use(World world, PlayerEntity player, Hand hand) { + HitResult mop = VecHelper.getObjectMouseOver(player, 5, 0); + + if (mop != null && mop.getType() == HitResult.Type.ENTITY) { + ItemStack stack = player.getStackInHand(hand); + + EntityHitResult ehr = ((EntityHitResult)mop); + + if (canFeedTo(stack, ehr.getEntity())) { + return onFedTo(stack, player, ehr.getEntity()); + } + } + + return super.use(world, player, hand); + } + + @Override + public ItemStack finishUsing(ItemStack stack, World w, LivingEntity player) { + stack = super.finishUsing(stack, w, player); + + player.damage(MagicalDamageSource.ZAP_APPLE, 120); + + if (w instanceof ServerWorld) { + ((ServerWorld) w).addLightning(new LightningEntity(w, player.x, player.y, player.z, false)); + } + + return stack; + } + + public boolean canFeedTo(ItemStack stack, Entity e) { + return e instanceof VillagerEntity + || e instanceof CreeperEntity + || e instanceof PigEntity; + } + + public TypedActionResult onFedTo(ItemStack stack, PlayerEntity player, Entity e) { + e.onStruckByLightning(new LightningEntity(e.world, e.x, e.y, e.z, false)); + + if (!player.abilities.creativeMode) { + stack.decrement(1); + } + + return new TypedActionResult<>(ActionResult.SUCCESS, stack); + } + + @Override + public void appendStacks(ItemGroup tab, DefaultedList items) { + super.appendStacks(tab, items); + if (isIn(tab)) { + ALIASABLE_ITEMS.forEach(item -> items.add(new ItemStack(item))); + } + } + + public Item getAppearance(ItemStack stack) { + if (stack.hasTag() && stack.getTag().containsKey("appearance")) { + return Registry.ITEM.get(new Identifier(stack.getTag().getString("appearance"))); + } + + return Items.AIR; + } + + @Override + public String getTranslationKey(ItemStack stack) { + Item appearance = getAppearance(stack); + return appearance == Items.AIR ? super.getTranslationKey() : appearance.getTranslationKey(stack); + } + + @Override + public Toxicity getToxicityLevel(ItemStack stack) { + return getAppearance(stack) == Items.AIR ? Toxicity.SEVERE : Toxicity.SAFE; + } + + @Override + public Rarity getRarity(ItemStack stack) { + if (getAppearance(stack) == Items.AIR) { + return Rarity.EPIC; + } + + return Rarity.RARE; + } +} diff --git a/src/main/java/com/minelittlepony/unicopia/item/consumables/UItemFoodDelegate.java b/src/main/java/com/minelittlepony/unicopia/item/consumables/DelegateFoodItem.java similarity index 79% rename from src/main/java/com/minelittlepony/unicopia/item/consumables/UItemFoodDelegate.java rename to src/main/java/com/minelittlepony/unicopia/item/consumables/DelegateFoodItem.java index 9392f9d4..793112ad 100644 --- a/src/main/java/com/minelittlepony/unicopia/item/consumables/UItemFoodDelegate.java +++ b/src/main/java/com/minelittlepony/unicopia/item/consumables/DelegateFoodItem.java @@ -6,27 +6,23 @@ import javax.annotation.Nonnull; import javax.annotation.Nullable; import net.minecraft.block.Block; -import net.minecraft.client.util.ITooltipFlag; import net.minecraft.entity.LivingEntity; import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.item.EnumAction; -import net.minecraft.item.ItemFood; -import net.minecraft.item.ItemMultiTexture; +import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.util.ActionResult; -import net.minecraft.util.EnumHand; import net.minecraft.world.World; -public class UItemFoodDelegate extends ItemMultiTexture implements IEdible { +public class DelegateFoodItem extends Item implements IEdible { @Nonnull private ItemFood foodItem = new ItemFood(0, 0, false); - public UItemFoodDelegate(Block block, ItemMultiTexture.Mapper mapper) { + public DelegateFoodItem(Block block, ItemMultiTexture.Mapper mapper) { super(block, block, mapper); } - public UItemFoodDelegate setFoodDelegate(@Nonnull ItemFood foodItem) { + public DelegateFoodItem setFoodDelegate(@Nonnull ItemFood foodItem) { this.foodItem = foodItem; return this; } diff --git a/src/main/java/com/minelittlepony/unicopia/item/consumables/MultiItemEdible.java b/src/main/java/com/minelittlepony/unicopia/item/consumables/DelegatedEdibleItem.java similarity index 72% rename from src/main/java/com/minelittlepony/unicopia/item/consumables/MultiItemEdible.java rename to src/main/java/com/minelittlepony/unicopia/item/consumables/DelegatedEdibleItem.java index ae84292b..aedf7448 100644 --- a/src/main/java/com/minelittlepony/unicopia/item/consumables/MultiItemEdible.java +++ b/src/main/java/com/minelittlepony/unicopia/item/consumables/DelegatedEdibleItem.java @@ -2,14 +2,16 @@ package com.minelittlepony.unicopia.item.consumables; import javax.annotation.Nonnull; import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.item.Item; import net.minecraft.item.ItemStack; +import net.minecraft.util.UseAction; -public class MultiItemEdible extends ItemEdible { +public class DelegatedEdibleItem extends EdibleItem { private final IEdible toxicityDeterminant; - public MultiItemEdible(Item.Settings settings, @Nonnull IEdible mapper) { - super(settings); + public DelegatedEdibleItem(Item.Settings settings, UseAction action, @Nonnull IEdible mapper) { + super(settings, action); toxicityDeterminant = mapper; } diff --git a/src/main/java/com/minelittlepony/unicopia/item/consumables/EdibleItem.java b/src/main/java/com/minelittlepony/unicopia/item/consumables/EdibleItem.java new file mode 100644 index 00000000..e8cd7cc4 --- /dev/null +++ b/src/main/java/com/minelittlepony/unicopia/item/consumables/EdibleItem.java @@ -0,0 +1,87 @@ +package com.minelittlepony.unicopia.item.consumables; + +import java.util.List; + +import javax.annotation.Nullable; + +import com.minelittlepony.unicopia.Race; +import com.minelittlepony.unicopia.SpeciesList; +import com.minelittlepony.unicopia.UEffects; + +import net.minecraft.client.item.TooltipContext; +import net.minecraft.entity.LivingEntity; +import net.minecraft.entity.effect.StatusEffectInstance; +import net.minecraft.entity.effect.StatusEffects; +import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.text.Text; +import net.minecraft.util.ActionResult; +import net.minecraft.util.Hand; +import net.minecraft.util.TypedActionResult; +import net.minecraft.util.UseAction; +import net.minecraft.world.World; + +public class EdibleItem extends Item implements IEdible { + + private final Toxicity toxicity; + + public EdibleItem(Item.Settings settings, Toxicity toxicity) { + super(settings); + this.toxicity = toxicity; + } + + @Override + public Toxicity getToxicityLevel(ItemStack stack) { + return toxicity; + } + + @Override + public UseAction getUseAction(ItemStack stack) { + return UseAction.EAT; + } + + @Override + public void appendTooltip(ItemStack stack, @Nullable World world, List tooltip, TooltipContext context) { + tooltip.add(getToxicityLevel(stack).getTooltip()); + } + + @Override + public ItemStack finishUsing(ItemStack stack, World world, LivingEntity entity) { + super.finishUsing(stack, world, entity); + + if (entity instanceof PlayerEntity) { + Race race = SpeciesList.instance().getPlayer((PlayerEntity)entity).getSpecies(); + Toxicity toxicity = (race.isDefault() || race == Race.CHANGELING) ? Toxicity.LETHAL : getToxicityLevel(stack); + + addSecondaryEffects((PlayerEntity)entity, toxicity, stack); + } + + return new ItemStack(getRecipeRemainder()); + } + + @Override + public TypedActionResult use(World world, PlayerEntity player, Hand hand) { + Race race = SpeciesList.instance().getPlayer(player).getSpecies(); + + if (race.isDefault() || race == Race.CHANGELING) { + return new TypedActionResult<>(ActionResult.FAIL, player.getStackInHand(hand)); + } + + return super.use(world, player, hand); + } + + @Override + public void addSecondaryEffects(PlayerEntity player, Toxicity toxicity, ItemStack stack) { + + if (toxicity.toxicWhenRaw()) { + player.addPotionEffect(toxicity.getPoisonEffect()); + } + + if (toxicity.isLethal()) { + player.addPotionEffect(new StatusEffectInstance(UEffects.FOOD_POISONING, 300, 7, false, false)); + } else if (toxicity.toxicWhenCooked()) { + player.addPotionEffect(new StatusEffectInstance(StatusEffects.NAUSEA, 3, 1, false, false)); + } + } +} diff --git a/src/main/java/com/minelittlepony/unicopia/item/consumables/ItemEdible.java b/src/main/java/com/minelittlepony/unicopia/item/consumables/ItemEdible.java deleted file mode 100644 index 74c354ed..00000000 --- a/src/main/java/com/minelittlepony/unicopia/item/consumables/ItemEdible.java +++ /dev/null @@ -1,121 +0,0 @@ -package com.minelittlepony.unicopia.item.consumables; - -import java.util.List; - -import javax.annotation.Nullable; - -import com.minelittlepony.unicopia.Race; -import com.minelittlepony.unicopia.SpeciesList; -import com.minelittlepony.unicopia.UEffects; - -import net.minecraft.advancement.criterion.Criterions; -import net.minecraft.client.item.TooltipContext; -import net.minecraft.entity.LivingEntity; -import net.minecraft.entity.effect.StatusEffectInstance; -import net.minecraft.entity.effect.StatusEffects; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.item.Item; -import net.minecraft.item.ItemStack; -import net.minecraft.potion.Potion; -import net.minecraft.potion.Potions; -import net.minecraft.server.network.ServerPlayerEntity; -import net.minecraft.sound.SoundCategory; -import net.minecraft.sound.SoundEvents; -import net.minecraft.text.Text; -import net.minecraft.util.ActionResult; -import net.minecraft.util.Hand; -import net.minecraft.util.TypedActionResult; -import net.minecraft.util.UseAction; -import net.minecraft.world.World; - -public abstract class ItemEdible extends Item implements IEdible { - - private UseAction useAction = UseAction.EAT; - - public ItemEdible(Item.Settings settings) { - super(settings); - } - - public Item setUseAction(UseAction action) { - useAction = action; - - return this; - } - - public UseAction getItemUseAction(ItemStack stack) { - return useAction; - } - - protected void onFoodEaten(ItemStack stack, World worldIn, PlayerEntity player) { - Race race = SpeciesList.instance().getPlayer(player).getSpecies(); - Toxicity toxicity = (race.isDefault() || race == Race.CHANGELING) ? Toxicity.LETHAL : getToxicityLevel(stack); - - addSecondaryEffects(player, toxicity, stack); - } - - @Override - public void appendTooltip(ItemStack stack, @Nullable World world, List tooltip, TooltipContext context) { - tooltip.add(getToxicityLevel(stack).getTooltip()); - } - - @Override - public ItemStack finishUsing(ItemStack stack, World world, LivingEntity entity) { - PlayerEntity player = entity instanceof PlayerEntity ? (PlayerEntity)entity : null; - - if (player != null) { - player.getHungerManager().eat(this, stack); - - world.playSound(null, player.x, player.y, player.z, SoundEvents.ENTITY_PLAYER_BURP, SoundCategory.PLAYERS, 0.5F, world.random.nextFloat() * 0.1F + 0.9F); - - onFoodEaten(stack, world, player); - - // replaced "this" with "stack.getItem()" - player.addStat(StatList.getObjectUseStats(stack.getItem())); - - if (player instanceof ServerPlayerEntity) { - Criterions.CONSUME_ITEM.handle((ServerPlayerEntity)player, stack); - } - } - - if (player == null || !player.abilities.creativeMode) { - stack.decrement(1); - } - - ItemStack container = getContainerItem(stack); - - if (!container.isEmpty() && player != null && !player.abilities.creativeMode) { - if (stack.isEmpty()) { - return getContainerItem(stack); - } - - player.inventory.addItemStackToInventory(getContainerItem(stack)); - } - - return stack; - } - - @Override - public TypedActionResult use(World world, PlayerEntity player, Hand hand) { - Race race = SpeciesList.instance().getPlayer(player).getSpecies(); - - if (race.isDefault() || race == Race.CHANGELING) { - return new TypedActionResult<>(ActionResult.FAIL, player.getStackInHand(hand)); - } - - return super.use(world, player, hand); - } - - @Override - public void addSecondaryEffects(PlayerEntity player, Toxicity toxicity, ItemStack stack) { - - if (toxicity.toxicWhenRaw()) { - player.addStatusEffectInstance(toxicity.getPoisonEffect()); - } - - if (toxicity.isLethal()) { - player.addStatusEffectInstance(new StatusEffectInstance(UEffects.FOOD_POISONING, 300, 7, false, false)); - } else if (toxicity.toxicWhenCooked()) { - player.addStatusEffectInstance(new StatusEffectInstance(StatusEffects.NAUSEA, 3, 1, false, false)); - } - } -} diff --git a/src/main/java/com/minelittlepony/unicopia/magic/Affinity.java b/src/main/java/com/minelittlepony/unicopia/magic/Affinity.java index 7e1166f4..b803f86d 100644 --- a/src/main/java/com/minelittlepony/unicopia/magic/Affinity.java +++ b/src/main/java/com/minelittlepony/unicopia/magic/Affinity.java @@ -1,5 +1,7 @@ package com.minelittlepony.unicopia.magic; +import net.minecraft.text.Text; +import net.minecraft.text.TranslatableText; import net.minecraft.util.Formatting; public enum Affinity { @@ -26,8 +28,10 @@ public enum Affinity { return this == BAD ? "curse" : "spell"; } - public String getUnlocalizedName() { - return "affinity." + getTranslationKey() + ".name"; + public Text getName() { + Text text = new TranslatableText("affinity." + getTranslationKey() + ".name"); + text.getStyle().setColor(getColourCode()); + return text; } public int getCorruption() { diff --git a/src/main/java/com/minelittlepony/unicopia/magic/ICaster.java b/src/main/java/com/minelittlepony/unicopia/magic/ICaster.java index ed5f8b47..827f9839 100644 --- a/src/main/java/com/minelittlepony/unicopia/magic/ICaster.java +++ b/src/main/java/com/minelittlepony/unicopia/magic/ICaster.java @@ -2,19 +2,15 @@ package com.minelittlepony.unicopia.magic; import java.util.Optional; import java.util.UUID; -import java.util.function.Consumer; import java.util.stream.Stream; import javax.annotation.Nullable; import com.minelittlepony.unicopia.entity.IOwned; import com.minelittlepony.util.VecHelper; -import com.minelittlepony.util.shape.IShape; - import net.minecraft.entity.Entity; import net.minecraft.entity.LivingEntity; import net.minecraft.entity.damage.DamageSource; -import net.minecraft.particle.ParticleEffect; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.Box; import net.minecraft.util.math.Vec3d; @@ -23,7 +19,7 @@ import net.minecraft.world.World; /** * Interface for any magically capable entities that can cast and persist spells. */ -public interface ICaster extends IOwned, ILevelled, IAffine, IMagicals { +public interface ICaster extends IOwned, ILevelled, IAffine, IMagicals, IParticleSource { void setEffect(@Nullable IMagicEffect effect); @@ -115,19 +111,6 @@ public interface ICaster extends IOwned, ILevelled, I return getEntity().getPos(); } - default void spawnParticles(ParticleEffect particleId, int count) { - // TODO: - // ParticleTypeRegistry.getInstance().getSpawner().spawnParticles(particleId, getEntity(), count); - } - - default void spawnParticles(IShape area, int count, Consumer particleSpawner) { - Vec3d pos = getOriginVector(); - - area.randomPoints(count, getWorld().random).stream() - .map(point -> point.add(pos)) - .forEach(particleSpawner); - } - default boolean subtractEnergyCost(double amount) { getOwner().damage(DamageSource.MAGIC, (int)amount/2); diff --git a/src/main/java/com/minelittlepony/unicopia/magic/IDispenceable.java b/src/main/java/com/minelittlepony/unicopia/magic/IDispenceable.java index 556a1a80..5137fbb2 100644 --- a/src/main/java/com/minelittlepony/unicopia/magic/IDispenceable.java +++ b/src/main/java/com/minelittlepony/unicopia/magic/IDispenceable.java @@ -1,6 +1,6 @@ package com.minelittlepony.unicopia.magic; -import com.minelittlepony.unicopia.magic.spells.SpellCastResult; +import com.minelittlepony.unicopia.magic.spells.CastResult; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.Direction; @@ -20,5 +20,5 @@ public interface IDispenceable extends IMagicEffect { * @param affinity The affinity of the casting artifact * @return an ActionResult for the type of action to perform. */ - SpellCastResult onDispenced(BlockPos pos, Direction facing, Position source, Affinity affinity); + CastResult onDispenced(BlockPos pos, Direction facing, Position source, Affinity affinity); } diff --git a/src/main/java/com/minelittlepony/unicopia/magic/IParticleSource.java b/src/main/java/com/minelittlepony/unicopia/magic/IParticleSource.java new file mode 100644 index 00000000..ce652f9a --- /dev/null +++ b/src/main/java/com/minelittlepony/unicopia/magic/IParticleSource.java @@ -0,0 +1,40 @@ +package com.minelittlepony.unicopia.magic; + +import java.util.function.Consumer; + +import com.minelittlepony.util.shape.IShape; + +import net.minecraft.particle.ParticleEffect; +import net.minecraft.util.math.Vec3d; +import net.minecraft.world.World; + +public interface IParticleSource { + + /** + * gets the minecraft world + */ + World getWorld(); + + /** + * Gets the center position where this caster is located. + */ + Vec3d getOriginVector(); + + default void spawnParticles(ParticleEffect particleId, int count) { + // TODO: + // ParticleTypeRegistry.getInstance().getSpawner().spawnParticles(particleId, getEntity(), count); + } + + default void spawnParticles(IShape area, int count, Consumer particleSpawner) { + Vec3d pos = getOriginVector(); + + area.randomPoints(count, getWorld().random).stream() + .map(point -> point.add(pos)) + .forEach(particleSpawner); + } + + default void addParticle(ParticleEffect effect, Vec3d position, Vec3d velocity) { + getWorld().addParticle(effect, position.x, position.y, position.z, velocity.x, velocity.y, velocity.z); + } + +} diff --git a/src/main/java/com/minelittlepony/unicopia/magic/ITossedEffect.java b/src/main/java/com/minelittlepony/unicopia/magic/ITossedEffect.java index 4ac89b4d..16da02ae 100644 --- a/src/main/java/com/minelittlepony/unicopia/magic/ITossedEffect.java +++ b/src/main/java/com/minelittlepony/unicopia/magic/ITossedEffect.java @@ -3,7 +3,7 @@ package com.minelittlepony.unicopia.magic; import javax.annotation.Nullable; import com.minelittlepony.unicopia.UItems; -import com.minelittlepony.unicopia.entity.AdvancedProjectileEntity; +import com.minelittlepony.unicopia.entity.ProjectileEntity; import com.minelittlepony.unicopia.magic.spells.SpellRegistry; import com.minelittlepony.unicopia.projectile.IAdvancedProjectile; import com.minelittlepony.unicopia.projectile.ITossable; @@ -49,7 +49,7 @@ public interface ITossedEffect extends IMagicEffect, ITossable> { world.playSound(null, entity.x, entity.y, entity.z, getThrowSound(caster), SoundCategory.NEUTRAL, 0.7F, 0.4F / (world.random.nextFloat() * 0.4F + 0.8F)); if (caster.isLocal()) { - IAdvancedProjectile projectile = new AdvancedProjectileEntity(null, world, caster.getOwner()); + IAdvancedProjectile projectile = new ProjectileEntity(null, world, caster.getOwner()); projectile.setItem(getCastAppearance(caster)); projectile.setThrowDamage(getThrowDamage(caster)); diff --git a/src/main/java/com/minelittlepony/unicopia/magic/IUseable.java b/src/main/java/com/minelittlepony/unicopia/magic/IUseable.java index 14b727c7..a6f27afb 100644 --- a/src/main/java/com/minelittlepony/unicopia/magic/IUseable.java +++ b/src/main/java/com/minelittlepony/unicopia/magic/IUseable.java @@ -2,7 +2,7 @@ package com.minelittlepony.unicopia.magic; import javax.annotation.Nullable; -import com.minelittlepony.unicopia.magic.spells.SpellCastResult; +import com.minelittlepony.unicopia.magic.spells.CastResult; import net.minecraft.entity.Entity; import net.minecraft.entity.player.PlayerEntity; @@ -31,7 +31,7 @@ public interface IUseable { * * @return ActionResult for the type of action to perform */ - SpellCastResult onUse(ItemUsageContext context, Affinity affinity); + CastResult onUse(ItemUsageContext context, Affinity affinity); /** * Triggered when the player right clicks @@ -44,5 +44,5 @@ public interface IUseable { * * @return ActionResult for the type of action to perform */ - SpellCastResult onUse(ItemStack stack, Affinity affinity, PlayerEntity player, World world, @Nullable Entity hitEntity); + CastResult onUse(ItemStack stack, Affinity affinity, PlayerEntity player, World world, @Nullable Entity hitEntity); } diff --git a/src/main/java/com/minelittlepony/unicopia/magic/items/ICastable.java b/src/main/java/com/minelittlepony/unicopia/magic/items/ICastable.java index b8025d55..f82dd88f 100644 --- a/src/main/java/com/minelittlepony/unicopia/magic/items/ICastable.java +++ b/src/main/java/com/minelittlepony/unicopia/magic/items/ICastable.java @@ -3,7 +3,7 @@ package com.minelittlepony.unicopia.magic.items; import com.minelittlepony.unicopia.entity.SpellcastEntity; import com.minelittlepony.unicopia.magic.IDispenceable; import com.minelittlepony.unicopia.magic.IMagicEffect; -import com.minelittlepony.unicopia.magic.spells.SpellCastResult; +import com.minelittlepony.unicopia.magic.spells.CastResult; import com.minelittlepony.unicopia.magic.spells.SpellRegistry; import net.minecraft.item.ItemStack; @@ -24,13 +24,13 @@ public interface ICastable extends IMagicalItem, IDispensable { return new TypedActionResult<>(ActionResult.FAIL, stack); } - SpellCastResult dispenceResult = onDispenseSpell(source, stack, effect); + CastResult dispenceResult = onDispenseSpell(source, stack, effect); - if (dispenceResult == SpellCastResult.DEFAULT) { + if (dispenceResult == CastResult.DEFAULT) { return new TypedActionResult<>(ActionResult.PASS, stack); } - if (dispenceResult == SpellCastResult.PLACE) { + if (dispenceResult == CastResult.PLACE) { castContainedSpell(source.getWorld(), source.getBlockPos(), stack, effect); stack.decrement(1); @@ -39,9 +39,9 @@ public interface ICastable extends IMagicalItem, IDispensable { return new TypedActionResult<>(ActionResult.SUCCESS, stack); } - SpellCastResult onDispenseSpell(BlockPointer source, ItemStack stack, IDispenceable effect); + CastResult onDispenseSpell(BlockPointer source, ItemStack stack, IDispenceable effect); - SpellCastResult onCastSpell(ItemUsageContext context, IMagicEffect effect); + CastResult onCastSpell(ItemUsageContext context, IMagicEffect effect); boolean canFeed(SpellcastEntity spell, ItemStack stack); diff --git a/src/main/java/com/minelittlepony/unicopia/magic/spells/AbstractAttachableSpell.java b/src/main/java/com/minelittlepony/unicopia/magic/spells/AbstractAttachableSpell.java index 76121c25..eed9f9d1 100644 --- a/src/main/java/com/minelittlepony/unicopia/magic/spells/AbstractAttachableSpell.java +++ b/src/main/java/com/minelittlepony/unicopia/magic/spells/AbstractAttachableSpell.java @@ -8,7 +8,9 @@ import javax.annotation.Nullable; import com.minelittlepony.unicopia.entity.SpellcastEntity; import com.minelittlepony.unicopia.magic.ICaster; +import net.minecraft.entity.Entity; import net.minecraft.nbt.CompoundTag; +import net.minecraft.server.world.ServerWorld; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.Box; @@ -43,10 +45,11 @@ public abstract class AbstractAttachableSpell extends AbstractSpell { @Nullable protected SpellcastEntity getTarget(ICaster source) { if (targettedEntity == null && targettedEntityId != null) { - source.getWorld().getEntities(SpellcastEntity.class, e -> e.getUuid().equals(targettedEntityId)) - .stream() - .findFirst() - .ifPresent(this::setTarget); + Entity e = ((ServerWorld)source.getWorld()).getEntity(targettedEntityId); + + if (e instanceof SpellcastEntity) { + setTarget((SpellcastEntity)e); + } } if (targettedEntity != null && targettedEntity.removed) { @@ -62,10 +65,12 @@ public abstract class AbstractAttachableSpell extends AbstractSpell { @Override public boolean update(ICaster source) { - if (searching) { - searchForTarget(source); - } else { - getTarget(source); + if (source.getWorld() instanceof ServerWorld) { + if (searching) { + searchForTarget(source); + } else { + getTarget(source); + } } return !isDead(); diff --git a/src/main/java/com/minelittlepony/unicopia/magic/spells/SpellVortex.java b/src/main/java/com/minelittlepony/unicopia/magic/spells/AttractiveSpell.java similarity index 79% rename from src/main/java/com/minelittlepony/unicopia/magic/spells/SpellVortex.java rename to src/main/java/com/minelittlepony/unicopia/magic/spells/AttractiveSpell.java index 86da50d5..85abdd44 100644 --- a/src/main/java/com/minelittlepony/unicopia/magic/spells/SpellVortex.java +++ b/src/main/java/com/minelittlepony/unicopia/magic/spells/AttractiveSpell.java @@ -9,9 +9,10 @@ import com.minelittlepony.util.shape.Sphere; import net.minecraft.entity.Entity; import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.util.math.MathHelper; import net.minecraft.util.math.Vec3d; -public class SpellVortex extends SpellShield { +public class AttractiveSpell extends SpellShield { @Override public String getName() { @@ -34,7 +35,7 @@ public class SpellVortex extends SpellShield { Vec3d pos = source.getOriginVector(); source.spawnParticles(new Sphere(false, range), range * 9, p -> { - ParticleTypeRegistry.getTnstance().spawnParticle(UParticles.UNICORN_MAGIC, false, p, p.subtract(pos), getTint()); + source.addParticle(UParticles.UNICORN_MAGIC, p, p.subtract(pos)); // getTint() }); } @@ -63,15 +64,14 @@ public class SpellVortex extends SpellShield { Vec3d vel = target.getVelocity(); - if (vel.x > maxVel) vel.x = maxVel; - if (vel.x < -maxVel) vel.x = -maxVel; - if (vel.y > maxVel) vel.y = maxVel; - if (vel.y < -maxVel) vel.y = -maxVel; - if (vel.z > maxVel) vel.z = maxVel; - if (vel.z < -maxVel) vel.z = -maxVel; + double x = MathHelper.clamp(vel.x, -maxVel, maxVel); + double y = MathHelper.clamp(vel.y, -maxVel, maxVel); + double z = MathHelper.clamp(vel.z, -maxVel, maxVel); if (distance < 0.5) { - vel.z += maxVel * 2; + z += maxVel * 2; } + + target.setVelocity(x, y, z); } } diff --git a/src/main/java/com/minelittlepony/unicopia/magic/spells/SpellAwkward.java b/src/main/java/com/minelittlepony/unicopia/magic/spells/AwkwardSpell.java similarity index 89% rename from src/main/java/com/minelittlepony/unicopia/magic/spells/SpellAwkward.java rename to src/main/java/com/minelittlepony/unicopia/magic/spells/AwkwardSpell.java index 732a18f1..46cc173e 100644 --- a/src/main/java/com/minelittlepony/unicopia/magic/spells/SpellAwkward.java +++ b/src/main/java/com/minelittlepony/unicopia/magic/spells/AwkwardSpell.java @@ -28,7 +28,7 @@ import net.minecraft.util.math.MathHelper; import net.minecraft.util.registry.Registry; import net.minecraft.world.World; -public class SpellAwkward extends AbstractSpell implements ITossedEffect, IUseable { +public class AwkwardSpell extends AbstractSpell implements ITossedEffect, IUseable { @Override public String getName() { @@ -85,15 +85,15 @@ public class SpellAwkward extends AbstractSpell implements ITossedEffect, IUseab } @Override - public SpellCastResult onUse(ItemUsageContext context, Affinity affinity) { - return SpellCastResult.PLACE; + public CastResult onUse(ItemUsageContext context, Affinity affinity) { + return CastResult.PLACE; } @Override - public SpellCastResult onUse(ItemStack stack, Affinity affinity, PlayerEntity player, World world, @Nullable Entity hitEntity) { + public CastResult onUse(ItemStack stack, Affinity affinity, PlayerEntity player, World world, @Nullable Entity hitEntity) { CasterUtils.toCaster(player).ifPresent(this::toss); - return SpellCastResult.NONE; + return CastResult.NONE; } } diff --git a/src/main/java/com/minelittlepony/unicopia/magic/spells/SpellCastResult.java b/src/main/java/com/minelittlepony/unicopia/magic/spells/CastResult.java similarity index 93% rename from src/main/java/com/minelittlepony/unicopia/magic/spells/SpellCastResult.java rename to src/main/java/com/minelittlepony/unicopia/magic/spells/CastResult.java index 429d5fa8..6d077c56 100644 --- a/src/main/java/com/minelittlepony/unicopia/magic/spells/SpellCastResult.java +++ b/src/main/java/com/minelittlepony/unicopia/magic/spells/CastResult.java @@ -3,7 +3,7 @@ package com.minelittlepony.unicopia.magic.spells; /** * A type of action to perform after a spell has completed its handling. */ -public enum SpellCastResult { +public enum CastResult { /** * No action. */ diff --git a/src/main/java/com/minelittlepony/unicopia/magic/spells/SpellChangelingTrap.java b/src/main/java/com/minelittlepony/unicopia/magic/spells/ChangelingTrapSpell.java similarity index 72% rename from src/main/java/com/minelittlepony/unicopia/magic/spells/SpellChangelingTrap.java rename to src/main/java/com/minelittlepony/unicopia/magic/spells/ChangelingTrapSpell.java index e7c19003..2d207f15 100644 --- a/src/main/java/com/minelittlepony/unicopia/magic/spells/SpellChangelingTrap.java +++ b/src/main/java/com/minelittlepony/unicopia/magic/spells/ChangelingTrapSpell.java @@ -1,17 +1,19 @@ package com.minelittlepony.unicopia.magic.spells; -import com.minelittlepony.unicopia.SpeciesList; +import java.util.Optional; + import com.minelittlepony.unicopia.UBlocks; +import com.minelittlepony.unicopia.UEntities; import com.minelittlepony.unicopia.USounds; -import com.minelittlepony.unicopia.entity.EntityCuccoon; +import com.minelittlepony.unicopia.entity.CuccoonEntity; import com.minelittlepony.unicopia.entity.IMagicals; import com.minelittlepony.unicopia.magic.Affinity; +import com.minelittlepony.unicopia.magic.CasterUtils; import com.minelittlepony.unicopia.magic.IAttachedEffect; import com.minelittlepony.unicopia.magic.ICaster; import com.minelittlepony.unicopia.magic.ITossedEffect; import com.minelittlepony.util.WorldEvent; -import net.minecraft.block.Block; import net.minecraft.block.BlockState; import net.minecraft.block.Blocks; import net.minecraft.entity.Entity; @@ -19,15 +21,18 @@ import net.minecraft.entity.LivingEntity; import net.minecraft.entity.effect.StatusEffectInstance; import net.minecraft.entity.effect.StatusEffects; import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.item.AutomaticItemPlacementContext; import net.minecraft.item.ItemStack; import net.minecraft.item.Items; import net.minecraft.nbt.CompoundTag; import net.minecraft.particle.ParticleTypes; import net.minecraft.sound.SoundEvent; import net.minecraft.sound.SoundEvents; +import net.minecraft.util.TagHelper; import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.Direction; -public class SpellChangelingTrap extends AbstractSpell implements ITossedEffect, IAttachedEffect { +public class ChangelingTrapSpell extends AbstractSpell implements ITossedEffect, IAttachedEffect { private BlockPos previousTrappedPosition; @@ -88,27 +93,28 @@ public class SpellChangelingTrap extends AbstractSpell implements ITossedEffect, setDirty(true); } - Block block = caster.getWorld().getBlockState(origin).getBlock(); + BlockState state = caster.getWorld().getBlockState(origin); + BlockState slimeState = UBlocks.slime_layer.getDefaultState(); - if (UBlocks.slime_layer.canPlaceBlockAt(caster.getWorld(), origin)) { - if (caster.getWorld().isAir(origin) || (block != UBlocks.slime_layer && block.isReplaceable(caster.getWorld(), origin))) { - caster.getWorld().setBlockState(origin, UBlocks.slime_layer.getDefaultState()); + if (slimeState.canPlaceAt(caster.getWorld(), origin)) { + if (caster.getWorld().isAir(origin) || (state.getBlock() != UBlocks.slime_layer && state.canReplace(new AutomaticItemPlacementContext(caster.getWorld(), origin, Direction.DOWN, new ItemStack(UBlocks.slime_layer), Direction.UP)))) { + caster.getWorld().setBlockState(origin, slimeState); } } } - entity.motionX = 0; + double yMotion = entity.getVelocity().y; - if (!entity.onGround && entity.motionY > 0) { - entity.motionY = 0; + if (!entity.onGround && yMotion > 0) { + yMotion = 0; } - entity.motionZ = 0; + entity.setVelocity(0, yMotion, 0); - entity.moveForward = 0; - entity.moveStrafing = 0; - entity.limbSwingAmount = 0; - entity.limbSwing = 0; - entity.prevLimbSwingAmount = 0; + entity.forwardSpeed = 0; + entity.sidewaysSpeed = 0; + entity.limbAngle = 0; + entity.limbDistance = 0; + entity.lastLimbDistance = 0; entity.x = Math.floor(entity.x) + 0.4; entity.z = Math.floor(entity.z) + 0.4; @@ -123,7 +129,7 @@ public class SpellChangelingTrap extends AbstractSpell implements ITossedEffect, StatusEffectInstance SLIME_REGEN = new StatusEffectInstance(StatusEffects.REGENERATION, 0); - entity.addStatusEffectInstance(SLIME_REGEN); + entity.addPotionEffect(SLIME_REGEN); if (caster.isLocal()) { if (struggleCounter <= 0) { @@ -160,11 +166,11 @@ public class SpellChangelingTrap extends AbstractSpell implements ITossedEffect, public void enforce(ICaster caster) { struggleCounter = 10; - if (caster.isLocal() && caster.getWorld().rand.nextInt(3) == 0) { + if (caster.isLocal() && caster.getWorld().random.nextInt(3) == 0) { setDead(); - EntityCuccoon cuccoon = new EntityCuccoon(caster.getWorld()); - cuccoon.copyLocationAndAnglesFrom(caster.getEntity()); + CuccoonEntity cuccoon = UEntities.CUCCOON.create(caster.getWorld()); + cuccoon.copyPositionAndRotation(caster.getEntity()); caster.getWorld().spawnEntity(cuccoon); } @@ -174,7 +180,7 @@ public class SpellChangelingTrap extends AbstractSpell implements ITossedEffect, protected void entrap(ICaster e) { - SpellChangelingTrap existing = e.getEffect(SpellChangelingTrap.class, true); + ChangelingTrapSpell existing = e.getEffect(ChangelingTrapSpell.class, true); if (existing == null) { e.setEffect(copy()); @@ -194,7 +200,9 @@ public class SpellChangelingTrap extends AbstractSpell implements ITossedEffect, if (caster.isLocal()) { caster.findAllEntitiesInRange(5) .filter(this::canAffect) - .map(e -> SpeciesList.instance().getCaster((LivingEntity)e)) + .map(e -> CasterUtils.toCaster(e)) + .filter(Optional::isPresent) + .map(Optional::get) .forEach(this::entrap); } } @@ -204,7 +212,7 @@ public class SpellChangelingTrap extends AbstractSpell implements ITossedEffect, super.toNBT(compound); if (previousTrappedPosition != null) { - compound.put("previousTrappedPosition", NBTUtils.createPosTag(previousTrappedPosition)); + compound.put("previousTrappedPosition", TagHelper.serializeBlockPos(previousTrappedPosition)); } compound.putInt("struggle", struggleCounter); } @@ -217,7 +225,7 @@ public class SpellChangelingTrap extends AbstractSpell implements ITossedEffect, struggleCounter = compound.getInt("struggle"); if (compound.containsKey("previousTrappedPosition")) { - previousTrappedPosition = NBTUtil.getPosFromTag(compound.getCompound("previousTrappedPosition")); + previousTrappedPosition = TagHelper.deserializeBlockPos(compound.getCompound("previousTrappedPosition")); } } } diff --git a/src/main/java/com/minelittlepony/unicopia/magic/spells/SpellCharge.java b/src/main/java/com/minelittlepony/unicopia/magic/spells/ChargingSpell.java similarity index 97% rename from src/main/java/com/minelittlepony/unicopia/magic/spells/SpellCharge.java rename to src/main/java/com/minelittlepony/unicopia/magic/spells/ChargingSpell.java index 8825f54a..90c97a5f 100644 --- a/src/main/java/com/minelittlepony/unicopia/magic/spells/SpellCharge.java +++ b/src/main/java/com/minelittlepony/unicopia/magic/spells/ChargingSpell.java @@ -9,7 +9,7 @@ import com.minelittlepony.util.shape.Line; import net.minecraft.util.math.Box; import net.minecraft.util.math.Vec3d; -public class SpellCharge extends AbstractAttachableSpell { +public class ChargingSpell extends AbstractAttachableSpell { private static final Box searchArea = new Box(-15, -15, -15, 15, 15, 15); diff --git a/src/main/java/com/minelittlepony/unicopia/magic/spells/SpellDarkness.java b/src/main/java/com/minelittlepony/unicopia/magic/spells/DarknessSpell.java similarity index 94% rename from src/main/java/com/minelittlepony/unicopia/magic/spells/SpellDarkness.java rename to src/main/java/com/minelittlepony/unicopia/magic/spells/DarknessSpell.java index aa355cf6..dcf20e78 100644 --- a/src/main/java/com/minelittlepony/unicopia/magic/spells/SpellDarkness.java +++ b/src/main/java/com/minelittlepony/unicopia/magic/spells/DarknessSpell.java @@ -14,8 +14,6 @@ import com.minelittlepony.util.shape.IShape; import com.minelittlepony.util.shape.Sphere; import net.minecraft.block.BlockState; -import net.minecraft.block.Blocks; -import net.minecraft.block.CactusBlock; import net.minecraft.block.Fertilizable; import net.minecraft.entity.Entity; import net.minecraft.entity.LivingEntity; @@ -30,7 +28,7 @@ import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.Box; import net.minecraft.util.math.Vec3d; -public class SpellDarkness extends AbstractAttachableSpell { +public class DarknessSpell extends AbstractAttachableSpell { private static final Box searchArea = new Box(-5, -5, -5, 5, 5, 5); @@ -82,7 +80,8 @@ public class SpellDarkness extends AbstractAttachableSpell { if (hasTarget()) { soundChance *= 10; - source.getEntity().getVelocity().y -= 0.01; + Vec3d vel = source.getEntity().getVelocity(); + source.getEntity().setVelocity(vel.x, vel.y - 0.01, vel.z); applyBlocks(source, radius); applyEntities(source, radius, e -> applyLight(source, e)); @@ -152,7 +151,7 @@ public class SpellDarkness extends AbstractAttachableSpell { } if (distance < 3 && entity.world.random.nextInt(30) == 0) { - entity.damage(MagicalDamageSource.create("darkness"), 3); + entity.damage(MagicalDamageSource.DARKNESS, 3); } } else { @@ -233,7 +232,9 @@ public class SpellDarkness extends AbstractAttachableSpell { double vX = (source.getWorld().random.nextFloat() - 0.5) * particleSpeed; double vZ = (source.getWorld().random.nextFloat() - 0.5) * particleSpeed; - ParticleTypeRegistry.getTnstance().spawnParticle(UParticles.SPHERE, true, pos, vX, 0, vZ, (int)(size * 1000), tint, 30); + source.getWorld().addParticle(UParticles.SPHERE, + pos.x, pos.y, pos.z, + vX, 0, vZ);//(int)(size * 1000), tint, 30 } } diff --git a/src/main/java/com/minelittlepony/unicopia/magic/spells/SpellPortal.java b/src/main/java/com/minelittlepony/unicopia/magic/spells/PortalSpell.java similarity index 90% rename from src/main/java/com/minelittlepony/unicopia/magic/spells/SpellPortal.java rename to src/main/java/com/minelittlepony/unicopia/magic/spells/PortalSpell.java index 5f60af2c..4395a219 100644 --- a/src/main/java/com/minelittlepony/unicopia/magic/spells/SpellPortal.java +++ b/src/main/java/com/minelittlepony/unicopia/magic/spells/PortalSpell.java @@ -31,7 +31,7 @@ import net.minecraft.util.math.Direction; import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; -public class SpellPortal extends AbstractSpell.RangedAreaSpell implements IUseable { +public class PortalSpell extends AbstractSpell.RangedAreaSpell implements IUseable { private static final IShape portalZone_X = new Sphere(true, 1, 0, 2, 1); private static final IShape portalZone_Y = new Sphere(true, 1, 2, 0, 2); @@ -41,7 +41,7 @@ public class SpellPortal extends AbstractSpell.RangedAreaSpell implements IUseab private static final Box TELEPORT_BOUNDS = new Box(-0.5, -0.5, -0.5, 0.5, 3, 0.5); @Nullable - private SpellPortal sibling = null; + private PortalSpell sibling = null; @Nullable private BlockPos position = null; @@ -85,7 +85,7 @@ public class SpellPortal extends AbstractSpell.RangedAreaSpell implements IUseab getDestinationPortal().ifPresent(IMagicEffect::setDead); } - private SpellPortal bridge; + private PortalSpell bridge; @Override public void onPlaced(ICaster caster) { @@ -104,13 +104,13 @@ public class SpellPortal extends AbstractSpell.RangedAreaSpell implements IUseab } @Override - public SpellCastResult onUse(ItemUsageContext context, Affinity affinity) { + public CastResult onUse(ItemUsageContext context, Affinity affinity) { position = context.getBlockPos().offset(context.getSide()); axis = context.getPlayerFacing().getAxis(); IPlayer prop = SpeciesList.instance().getPlayer(context.getPlayer()); - SpellPortal other = prop.getEffect(SpellPortal.class, true); + PortalSpell other = prop.getEffect(PortalSpell.class, true); if (other != null) { other.getActualInstance().setDestinationPortal(this); @@ -119,21 +119,21 @@ public class SpellPortal extends AbstractSpell.RangedAreaSpell implements IUseab } } else { if (!world.isClient) { - bridge = (SpellPortal)copy(); + bridge = (PortalSpell)copy(); prop.setEffect(bridge); } } - return SpellCastResult.PLACE; + return CastResult.PLACE; } @Override - public SpellCastResult onUse(ItemStack stack, Affinity affinity, PlayerEntity player, World world, @Nullable Entity hitEntity) { - return SpellCastResult.NONE; + public CastResult onUse(ItemStack stack, Affinity affinity, PlayerEntity player, World world, @Nullable Entity hitEntity) { + return CastResult.NONE; } - public void setDestinationPortal(SpellPortal other) { + public void setDestinationPortal(PortalSpell other) { if (!getDestinationPortal().isPresent()) { sibling = other; other.sibling = this; @@ -187,7 +187,7 @@ public class SpellPortal extends AbstractSpell.RangedAreaSpell implements IUseab return !(i instanceof IMagicals) && i.portalCooldown == 0; } - protected void teleportEntity(ICaster source, SpellPortal dest, Entity i) { + protected void teleportEntity(ICaster source, PortalSpell dest, Entity i) { Direction.Axis xi = i.getHorizontalFacing().getAxis(); if (axis != Direction.Axis.Y && xi != axis) { @@ -223,7 +223,7 @@ public class SpellPortal extends AbstractSpell.RangedAreaSpell implements IUseab /** * Converts a possibly dead portal effect into a live one by forcing the owner entity to load. */ - protected SpellPortal getActualInstance() { + protected PortalSpell getActualInstance() { if (world instanceof ServerWorld) { Entity i = ((ServerWorld)world).getEntity(casterId); @@ -235,8 +235,8 @@ public class SpellPortal extends AbstractSpell.RangedAreaSpell implements IUseab if (i instanceof SpellcastEntity) { IMagicEffect effect = ((SpellcastEntity) i).getEffect(); - if (effect instanceof SpellPortal) { - return (SpellPortal)effect; + if (effect instanceof PortalSpell) { + return (PortalSpell)effect; } } } @@ -247,7 +247,7 @@ public class SpellPortal extends AbstractSpell.RangedAreaSpell implements IUseab /** * Gets or loads the destination portal. */ - public Optional getDestinationPortal() { + public Optional getDestinationPortal() { if (isDead()) { return Optional.empty(); @@ -273,8 +273,8 @@ public class SpellPortal extends AbstractSpell.RangedAreaSpell implements IUseab if (i instanceof SpellcastEntity) { IMagicEffect effect = ((SpellcastEntity) i).getEffect(); - if (effect instanceof SpellPortal) { - sibling = (SpellPortal)effect; + if (effect instanceof PortalSpell) { + sibling = (PortalSpell)effect; } } diff --git a/src/main/java/com/minelittlepony/unicopia/magic/spells/SpellSiphon.java b/src/main/java/com/minelittlepony/unicopia/magic/spells/SiphoningSpell.java similarity index 98% rename from src/main/java/com/minelittlepony/unicopia/magic/spells/SpellSiphon.java rename to src/main/java/com/minelittlepony/unicopia/magic/spells/SiphoningSpell.java index 67635cff..cf084159 100644 --- a/src/main/java/com/minelittlepony/unicopia/magic/spells/SpellSiphon.java +++ b/src/main/java/com/minelittlepony/unicopia/magic/spells/SiphoningSpell.java @@ -18,7 +18,7 @@ import net.minecraft.particle.ParticleTypes; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.Vec3d; -public class SpellSiphon extends AbstractSpell.RangedAreaSpell { +public class SiphoningSpell extends AbstractSpell.RangedAreaSpell { @Override public String getName() { diff --git a/src/main/java/com/minelittlepony/unicopia/magic/spells/SpellDisguise.java b/src/main/java/com/minelittlepony/unicopia/magic/spells/SpellDisguise.java index 73041487..feedd419 100644 --- a/src/main/java/com/minelittlepony/unicopia/magic/spells/SpellDisguise.java +++ b/src/main/java/com/minelittlepony/unicopia/magic/spells/SpellDisguise.java @@ -5,9 +5,9 @@ import java.util.UUID; import javax.annotation.Nonnull; import javax.annotation.Nullable; +import com.minelittlepony.unicopia.InteractionManager; import com.minelittlepony.unicopia.Race; import com.minelittlepony.unicopia.SpeciesList; -import com.minelittlepony.unicopia.UClient; import com.minelittlepony.unicopia.UParticles; import com.minelittlepony.unicopia.ability.IFlyingPredicate; import com.minelittlepony.unicopia.ability.IHeightPredicate; @@ -28,6 +28,7 @@ import net.minecraft.entity.EntityType; import net.minecraft.entity.EquipmentSlot; import net.minecraft.entity.FallingBlockEntity; import net.minecraft.entity.LivingEntity; +import net.minecraft.entity.ai.RangedAttackMob; import net.minecraft.entity.boss.dragon.EnderDragonEntity; import net.minecraft.entity.decoration.AbstractDecorationEntity; import net.minecraft.entity.mob.AmbientEntity; @@ -147,7 +148,7 @@ public class SpellDisguise extends AbstractSpell implements IAttachedEffect, ISu protected synchronized void createPlayer(CompoundTag nbt, GameProfile profile, ICaster source) { removeDisguise(); - entity = UClient.instance().createPlayer(source.getEntity(), profile); + entity = InteractionManager.instance().createPlayer(source.getEntity(), profile); entity.setCustomName(source.getOwner().getName()); ((PlayerEntity)entity).fromTag(nbt.getCompound("playerNbt")); entity.setUuid(UUID.randomUUID()); @@ -273,10 +274,10 @@ public class SpellDisguise extends AbstractSpell implements IAttachedEffect, ISu } } - if (to instanceof IRangedAttackMob) { + if (to instanceof RangedAttackMob) { ItemStack activeItem = from.getActiveItemStack(); - ((IRangedAttackMob)to).setSwingingArms(!activeItem.isEmpty() && activeItem.getUseAction() == UseAction.BOW); + ((RangedAttackMob)to).setSwingingArms(!activeItem.isEmpty() && activeItem.getUseAction() == UseAction.BOW); } if (to instanceof TameableEntity) { @@ -401,7 +402,7 @@ public class SpellDisguise extends AbstractSpell implements IAttachedEffect, ISu entity.getDataTracker().set(MixinEntity.Player.getModelFlag(), owner.getDataTracker().get(MixinEntity.Player.getModelFlag())); } - if (player.isClientPlayer() && UClient.instance().getViewMode() == 0) { + if (player.isClientPlayer() && InteractionManager.instance().getViewMode() == 0) { entity.setInvisible(true); entity.y = Integer.MIN_VALUE; } diff --git a/src/main/java/com/minelittlepony/unicopia/magic/spells/SpellFire.java b/src/main/java/com/minelittlepony/unicopia/magic/spells/SpellFire.java index 5be268e5..0aa90048 100644 --- a/src/main/java/com/minelittlepony/unicopia/magic/spells/SpellFire.java +++ b/src/main/java/com/minelittlepony/unicopia/magic/spells/SpellFire.java @@ -98,7 +98,7 @@ public class SpellFire extends AbstractSpell.RangedAreaSpell implements IUseable } @Override - public SpellCastResult onUse(ItemStack stack, Affinity affinity, PlayerEntity player, World world, BlockPos pos, Direction side, float hitX, float hitY, float hitZ) { + public CastResult onUse(ItemStack stack, Affinity affinity, PlayerEntity player, World world, BlockPos pos, Direction side, float hitX, float hitY, float hitZ) { boolean result = false; if (player == null || player.isSneaking()) { @@ -114,20 +114,20 @@ public class SpellFire extends AbstractSpell.RangedAreaSpell implements IUseable result = applyEntities(player, world, pos); } - return result ? SpellCastResult.DEFAULT : SpellCastResult.NONE; + return result ? CastResult.DEFAULT : CastResult.NONE; } @Override - public SpellCastResult onUse(ItemStack stack, Affinity affinity, PlayerEntity player, World world, @Nullable Entity hitEntity) { + public CastResult onUse(ItemStack stack, Affinity affinity, PlayerEntity player, World world, @Nullable Entity hitEntity) { if (hitEntity == null) { - return SpellCastResult.NONE; + return CastResult.NONE; } - return applyEntitySingle(player, world, hitEntity) ? SpellCastResult.DEFAULT : SpellCastResult.NONE; + return applyEntitySingle(player, world, hitEntity) ? CastResult.DEFAULT : CastResult.NONE; } @Override - public SpellCastResult onDispenced(BlockPos pos, Direction facing, IBlockSource source, Affinity affinity) { + public CastResult onDispenced(BlockPos pos, Direction facing, IBlockSource source, Affinity affinity) { pos = pos.offset(facing, 4); boolean result = false; @@ -140,7 +140,7 @@ public class SpellFire extends AbstractSpell.RangedAreaSpell implements IUseable result = applyEntities(null, source.getWorld(), pos); } - return result ? SpellCastResult.NONE : SpellCastResult.DEFAULT; + return result ? CastResult.NONE : CastResult.DEFAULT; } protected boolean applyBlocks(World world, BlockPos pos) { diff --git a/src/main/java/com/minelittlepony/unicopia/magic/spells/SpellIce.java b/src/main/java/com/minelittlepony/unicopia/magic/spells/SpellIce.java index c30e561b..4554ce09 100644 --- a/src/main/java/com/minelittlepony/unicopia/magic/spells/SpellIce.java +++ b/src/main/java/com/minelittlepony/unicopia/magic/spells/SpellIce.java @@ -86,28 +86,28 @@ public class SpellIce extends AbstractSpell.RangedAreaSpell implements IUseable, } @Override - public SpellCastResult onDispenced(BlockPos pos, Direction facing, IBlockSource source, Affinity affinity) { - return applyBlocks(null, source.getWorld(), pos.offset(facing, rad)) ? SpellCastResult.NONE : SpellCastResult.DEFAULT; + public CastResult onDispenced(BlockPos pos, Direction facing, IBlockSource source, Affinity affinity) { + return applyBlocks(null, source.getWorld(), pos.offset(facing, rad)) ? CastResult.NONE : CastResult.DEFAULT; } @Override - public SpellCastResult onUse(ItemStack stack, Affinity affinity, PlayerEntity player, World world, BlockPos pos, Direction side, float hitX, float hitY, float hitZ) { + public CastResult onUse(ItemStack stack, Affinity affinity, PlayerEntity player, World world, BlockPos pos, Direction side, float hitX, float hitY, float hitZ) { if (player != null && player.isSneaking()) { applyBlockSingle(world, pos); } else { applyBlocks(player, world, pos); } - return SpellCastResult.DEFAULT; + return CastResult.DEFAULT; } @Override - public SpellCastResult onUse(ItemStack stack, Affinity affinity, PlayerEntity player, World world, @Nullable Entity hitEntity) { + public CastResult onUse(ItemStack stack, Affinity affinity, PlayerEntity player, World world, @Nullable Entity hitEntity) { if (hitEntity != null && applyEntitySingle(player, hitEntity)) { - return SpellCastResult.DEFAULT; + return CastResult.DEFAULT; } - return SpellCastResult.NONE; + return CastResult.NONE; } private boolean applyBlocks(PlayerEntity owner, World world, BlockPos pos) { diff --git a/src/main/java/com/minelittlepony/unicopia/magic/spells/SpellInferno.java b/src/main/java/com/minelittlepony/unicopia/magic/spells/SpellInferno.java index 2683f0d2..092ebdfe 100644 --- a/src/main/java/com/minelittlepony/unicopia/magic/spells/SpellInferno.java +++ b/src/main/java/com/minelittlepony/unicopia/magic/spells/SpellInferno.java @@ -64,8 +64,8 @@ public class SpellInferno extends SpellFire { } @Override - public SpellCastResult onUse(ItemStack stack, Affinity affinity, PlayerEntity player, World world, BlockPos pos, Direction side, float hitX, float hitY, float hitZ) { - return SpellCastResult.PLACE; + public CastResult onUse(ItemStack stack, Affinity affinity, PlayerEntity player, World world, BlockPos pos, Direction side, float hitX, float hitY, float hitZ) { + return CastResult.PLACE; } @Override diff --git a/src/main/java/com/minelittlepony/unicopia/magic/spells/SpellRegistry.java b/src/main/java/com/minelittlepony/unicopia/magic/spells/SpellRegistry.java index f7c4d2ce..faf8fa56 100644 --- a/src/main/java/com/minelittlepony/unicopia/magic/spells/SpellRegistry.java +++ b/src/main/java/com/minelittlepony/unicopia/magic/spells/SpellRegistry.java @@ -34,22 +34,22 @@ public class SpellRegistry { private SpellRegistry() { registerSpell(SpellShield::new); - registerSpell(SpellCharge::new); + registerSpell(ChargingSpell::new); registerSpell(SpellFire::new); registerSpell(SpellIce::new); - registerSpell(SpellPortal::new); - registerSpell(SpellVortex::new); + registerSpell(PortalSpell::new); + registerSpell(AttractiveSpell::new); registerSpell(SpellDisguise::new); registerSpell(SpellNecromancy::new); - registerSpell(SpellAwkward::new); + registerSpell(AwkwardSpell::new); registerSpell(SpellInferno::new); registerSpell(SpellDrake::new); registerSpell(SpellReveal::new); - registerSpell(SpellDarkness::new); + registerSpell(DarknessSpell::new); registerSpell(SpellFlame::new); - registerSpell(SpellSiphon::new); + registerSpell(SiphoningSpell::new); registerSpell(SpellLight::new); - registerSpell(SpellChangelingTrap::new); + registerSpell(ChangelingTrapSpell::new); registerSpell(SpellScorch::new); } diff --git a/src/main/java/com/minelittlepony/unicopia/magic/spells/SpellScorch.java b/src/main/java/com/minelittlepony/unicopia/magic/spells/SpellScorch.java index 886b3511..1758d22d 100644 --- a/src/main/java/com/minelittlepony/unicopia/magic/spells/SpellScorch.java +++ b/src/main/java/com/minelittlepony/unicopia/magic/spells/SpellScorch.java @@ -3,7 +3,7 @@ package com.minelittlepony.unicopia.magic.spells; import javax.annotation.Nullable; import com.minelittlepony.unicopia.UParticles; -import com.minelittlepony.unicopia.entity.AdvancedProjectileEntity; +import com.minelittlepony.unicopia.entity.ProjectileEntity; import com.minelittlepony.unicopia.magic.Affinity; import com.minelittlepony.unicopia.magic.ICaster; import com.minelittlepony.unicopia.magic.ITossedEffect; diff --git a/src/main/java/com/minelittlepony/unicopia/mixin/MixinItemEntity.java b/src/main/java/com/minelittlepony/unicopia/mixin/MixinItemEntity.java index b94e88f1..fcda2a1f 100644 --- a/src/main/java/com/minelittlepony/unicopia/mixin/MixinItemEntity.java +++ b/src/main/java/com/minelittlepony/unicopia/mixin/MixinItemEntity.java @@ -1,41 +1,51 @@ package com.minelittlepony.unicopia.mixin; import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.gen.Accessor; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -import com.minelittlepony.unicopia.ducks.IRaceContainerHolder; -import com.minelittlepony.unicopia.entity.IEntity; +import com.minelittlepony.unicopia.ducks.IItemEntity; import com.minelittlepony.unicopia.entity.capabilities.ItemEntityCapabilities; import net.minecraft.entity.Entity; import net.minecraft.entity.ItemEntity; @Mixin(ItemEntity.class) -public abstract class MixinItemEntity extends Entity implements IRaceContainerHolder { +public abstract class MixinItemEntity extends Entity implements IItemEntity { - private final IEntity caster = createRaceContainer(); + private final ItemEntityCapabilities caster = createRaceContainer(); private MixinItemEntity() { super(null, null); } @Override - public IEntity createRaceContainer() { + public ItemEntityCapabilities createRaceContainer() { return new ItemEntityCapabilities((ItemEntity)(Object)this); } @Override - public IEntity getRaceContainer() { + public ItemEntityCapabilities getRaceContainer() { return caster; } - @Inject(method = "tick()V", at = @At("HEAD")) + @Inject(method = "tick()V", at = @At("HEAD"), cancellable = true) private void beforeTick(CallbackInfo info) { - caster.beforeUpdate(); + if (caster.beforeUpdate()) { + info.cancel(); + } } @Inject(method = "tick()V", at = @At("RETURN")) private void afterTick(CallbackInfo info) { caster.onUpdate(); } + + @Accessor("age") + @Override + public abstract int getAge(); + + @Accessor("pickupDelay") + @Override + public abstract int getPickupDelay(); } diff --git a/src/main/java/com/minelittlepony/unicopia/mixin/MixinPlayerEntity.java b/src/main/java/com/minelittlepony/unicopia/mixin/MixinPlayerEntity.java index 4e343de6..1da86890 100644 --- a/src/main/java/com/minelittlepony/unicopia/mixin/MixinPlayerEntity.java +++ b/src/main/java/com/minelittlepony/unicopia/mixin/MixinPlayerEntity.java @@ -4,6 +4,7 @@ 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.ModifyArg; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; import com.minelittlepony.unicopia.SpeciesList; @@ -19,10 +20,10 @@ import net.minecraft.entity.player.PlayerEntity; import net.minecraft.item.ItemStack; import net.minecraft.util.Unit; import net.minecraft.util.math.BlockPos; +import net.minecraft.world.GameMode; @Mixin(PlayerEntity.class) public abstract class MixinPlayerEntity extends LivingEntity implements IRaceContainerHolder { - private MixinPlayerEntity() { super(null, null); } @Override @@ -55,4 +56,10 @@ public abstract class MixinPlayerEntity extends LivingEntity implements IRaceCon o.getRaceContainer().setSpecies(getRaceContainer().getSpecies()); }); } + + @Inject(method = "setGameMode(Lnet/minecraft/world/GameMode;)V", + at = @At("RETURN")) + public void setGameMode(GameMode mode, CallbackInfo info) { + getRaceContainer().setSpecies(getRaceContainer().getSpecies()); + } } diff --git a/src/main/java/com/minelittlepony/unicopia/network/MsgPlayerAbility.java b/src/main/java/com/minelittlepony/unicopia/network/MsgPlayerAbility.java index a27791ac..00b07d72 100644 --- a/src/main/java/com/minelittlepony/unicopia/network/MsgPlayerAbility.java +++ b/src/main/java/com/minelittlepony/unicopia/network/MsgPlayerAbility.java @@ -5,6 +5,8 @@ import java.util.UUID; import com.google.gson.Gson; import com.google.gson.GsonBuilder; import com.google.gson.annotations.Expose; +import com.minelittlepony.jumpingcastle.api.Channel; +import com.minelittlepony.jumpingcastle.api.Message; import com.minelittlepony.unicopia.SpeciesList; import com.minelittlepony.unicopia.ability.IData; import com.minelittlepony.unicopia.ability.IPower; @@ -12,8 +14,9 @@ import com.minelittlepony.unicopia.ability.PowersRegistry; import com.minelittlepony.unicopia.entity.capabilities.IPlayer; import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.server.MinecraftServer; -public class MsgPlayerAbility { +public class MsgPlayerAbility implements Message, Message.Handler { private static final Gson gson = new GsonBuilder() .excludeFieldsWithoutExposeAnnotation() @@ -34,8 +37,9 @@ public class MsgPlayerAbility { abilityJson = gson.toJson(data, power.getPackageType()); } - private void apply(IPower power) { - IPlayer player = SpeciesList.instance().getPlayer(senderId); + private void apply(IPower power, Channel channel) { + MinecraftServer server = channel.getServer(); + IPlayer player = SpeciesList.instance().getPlayer(server.getPlayerManager().getPlayer(senderId)); if (player == null) { return; } @@ -46,7 +50,7 @@ public class MsgPlayerAbility { } @Override - public void onPayload(MsgPlayerAbility message, IChannel channel) { - PowersRegistry.instance().getPowerFromName(powerIdentifier).ifPresent(this::apply); + public void onPayload(MsgPlayerAbility message, Channel channel) { + PowersRegistry.instance().getPowerFromName(powerIdentifier).ifPresent(power -> apply(power, channel)); } } diff --git a/src/main/java/com/minelittlepony/unicopia/network/MsgPlayerCapabilities.java b/src/main/java/com/minelittlepony/unicopia/network/MsgPlayerCapabilities.java index c4acd8e2..860880a3 100644 --- a/src/main/java/com/minelittlepony/unicopia/network/MsgPlayerCapabilities.java +++ b/src/main/java/com/minelittlepony/unicopia/network/MsgPlayerCapabilities.java @@ -8,21 +8,19 @@ import java.io.IOException; import java.util.UUID; import com.google.gson.annotations.Expose; -import com.minelittlepony.jumpingcastle.api.IChannel; -import com.minelittlepony.jumpingcastle.api.IMessage; -import com.minelittlepony.jumpingcastle.api.IMessageHandler; +import com.minelittlepony.jumpingcastle.api.Channel; +import com.minelittlepony.jumpingcastle.api.Message; import com.minelittlepony.unicopia.Race; import com.minelittlepony.unicopia.SpeciesList; -import com.minelittlepony.unicopia.UClient; import com.minelittlepony.unicopia.Unicopia; import com.minelittlepony.unicopia.entity.capabilities.IPlayer; import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.nbt.CompressedStreamTools; +import net.minecraft.server.MinecraftServer; import net.minecraft.nbt.CompoundTag; +import net.minecraft.nbt.NbtIo; -@IMessage.Id(1) -public class MsgPlayerCapabilities implements IMessage, IMessageHandler { +public class MsgPlayerCapabilities implements Message, Message.Handler { @Expose Race newRace; @@ -34,18 +32,18 @@ public class MsgPlayerCapabilities implements IMessage, IMessageHandler 0) { try (ByteArrayInputStream input = new ByteArrayInputStream(compoundTag)) { - CompoundTag nbt = CompressedStreamTools.read(new DataInputStream(input)); + CompoundTag nbt = NbtIo.read(new DataInputStream(input)); player.fromNBT(nbt); } catch (IOException e) { diff --git a/src/main/java/com/minelittlepony/unicopia/network/MsgRequestCapabilities.java b/src/main/java/com/minelittlepony/unicopia/network/MsgRequestCapabilities.java index ac59ee15..1600a44e 100644 --- a/src/main/java/com/minelittlepony/unicopia/network/MsgRequestCapabilities.java +++ b/src/main/java/com/minelittlepony/unicopia/network/MsgRequestCapabilities.java @@ -3,18 +3,17 @@ package com.minelittlepony.unicopia.network; import java.util.UUID; import com.google.gson.annotations.Expose; -import com.minelittlepony.jumpingcastle.api.IChannel; -import com.minelittlepony.jumpingcastle.api.IMessage; -import com.minelittlepony.jumpingcastle.api.IMessageHandler; +import com.minelittlepony.jumpingcastle.api.Channel; +import com.minelittlepony.jumpingcastle.api.Message; import com.minelittlepony.unicopia.Race; import com.minelittlepony.unicopia.SpeciesList; import com.minelittlepony.unicopia.Unicopia; import com.minelittlepony.unicopia.entity.capabilities.IPlayer; import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.server.MinecraftServer; -@IMessage.Id(0) -public class MsgRequestCapabilities implements IMessage, IMessageHandler { +public class MsgRequestCapabilities implements Message, Message.Handler { @Expose public UUID senderId; @@ -27,9 +26,11 @@ public class MsgRequestCapabilities implements IMessage, IMessageHandler, IDispensable { @Nullable default IAdvancedProjectile createProjectile(World world, PlayerEntity player) { - return new AdvancedProjectileEntity(null, world, player); + return new ProjectileEntity(null, world, player); } @Nullable default IAdvancedProjectile createProjectile(World world, Position pos) { - return new AdvancedProjectileEntity(null, world, pos.getX(), pos.getY(), pos.getZ()); + return new ProjectileEntity(null, world, pos.getX(), pos.getY(), pos.getZ()); } default void toss(World world, ItemStack itemstack, PlayerEntity player) { diff --git a/src/main/java/com/minelittlepony/unicopia/util/crafting/CraftingManager.java b/src/main/java/com/minelittlepony/unicopia/util/crafting/CraftingManager.java deleted file mode 100644 index 49667b36..00000000 --- a/src/main/java/com/minelittlepony/unicopia/util/crafting/CraftingManager.java +++ /dev/null @@ -1,124 +0,0 @@ -package com.minelittlepony.unicopia.util.crafting; - -import java.util.Collection; -import java.util.Map; -import java.util.function.Function; - -import javax.annotation.Nonnull; -import javax.annotation.Nullable; - -import com.google.common.collect.Maps; -import com.google.gson.JsonObject; -import com.google.gson.JsonParseException; -import com.google.gson.JsonSyntaxException; -import com.minelittlepony.util.AssetWalker; - -import net.minecraft.inventory.CraftingInventory; -import net.minecraft.item.ItemStack; -import net.minecraft.recipe.Recipe; -import net.minecraft.util.DefaultedList; -import net.minecraft.util.Identifier; -import net.minecraft.util.JsonHelper; -import net.minecraft.world.World; - -public class CraftingManager { - - private final Map> REGISTRY = Maps.newHashMap(); - - private final Map>> JSON_PARSERS = Maps.newHashMap(); - - @Nonnull - private final Identifier crafting_id; - - private final AssetWalker assets; - - public CraftingManager(String modid, String resourcename) { - this(new Identifier(modid, resourcename + "/recipes")); - } - - public CraftingManager(@Nonnull Identifier id) { - crafting_id = id; - assets = new AssetWalker(id, this::handleJson); - } - - protected void handleJson(Identifier id, JsonObject json) throws JsonParseException { - REGISTRY.put(id, parseRecipeJson(json)); - } - - protected void registerRecipeTypes(Map>> types) { - types.put("crafting_shaped", ShapedRecipes::deserialize); - types.put("crafting_shapeless", ShapelessRecipes::deserialize); - } - - public void load() { - JSON_PARSERS.clear(); - REGISTRY.clear(); - - registerRecipeTypes(JSON_PARSERS); - - assets.walk(); - } - - protected Recipe parseRecipeJson(JsonObject json) { - String s = JsonHelper.getString(json, "type"); - - if (!JSON_PARSERS.containsKey(s)) { - throw new JsonSyntaxException("Invalid or unsupported recipe type '" + s + "'"); - } - - return JSON_PARSERS.get(s).apply(json); - } - - @Deprecated - @Nonnull - public ItemStack findMatchingResult(CraftingInventory craftMatrix, World worldIn) { - Recipe recipe = findMatchingRecipe(craftMatrix, worldIn); - - if (recipe != null) { - return recipe.getCraftingResult(craftMatrix); - } - - return ItemStack.EMPTY; - } - - @Deprecated - @Nullable - public Recipe findMatchingRecipe(CraftingInventory craftMatrix, World world) { - for (Recipe irecipe : getRecipes()) { - if (irecipe.matches(craftMatrix, world)) { - return irecipe; - } - } - - return null; - } - - @Deprecated - public Collection> getRecipes() { - if (REGISTRY.isEmpty()) { - load(); - } - return REGISTRY.values(); - } - - @Deprecated - public DefaultedList getRemainingItems(CraftingInventory craftMatrix, World worldIn) { - Recipe recipe = findMatchingRecipe(craftMatrix, worldIn); - - if (recipe != null) { - return recipe.getRemainingItems(craftMatrix); - } - - return cloneInventoryContents(craftMatrix); - } - - public static DefaultedList cloneInventoryContents(CraftingInventory craftMatrix) { - DefaultedList result = DefaultedList.ofSize(craftMatrix.getInvSize(), ItemStack.EMPTY); - - for (int i = 0; i < result.size(); ++i) { - result.set(i, craftMatrix.getInvStack(i)); - } - - return result; - } -} diff --git a/src/main/java/com/minelittlepony/unicopia/world/structure/CustomSaplingGenerator.java b/src/main/java/com/minelittlepony/unicopia/world/structure/CustomSaplingGenerator.java new file mode 100644 index 00000000..ba795979 --- /dev/null +++ b/src/main/java/com/minelittlepony/unicopia/world/structure/CustomSaplingGenerator.java @@ -0,0 +1,30 @@ +package com.minelittlepony.unicopia.world.structure; + +import java.util.Random; +import javax.annotation.Nullable; + +import net.minecraft.block.BlockState; +import net.minecraft.block.sapling.SaplingGenerator; +import net.minecraft.world.gen.feature.AbstractTreeFeature; +import net.minecraft.world.gen.feature.DefaultFeatureConfig; +import net.minecraft.world.gen.feature.OakTreeFeature; + +public class CustomSaplingGenerator extends SaplingGenerator { + + private final int height; + + private final BlockState log; + private final BlockState leaves; + + public CustomSaplingGenerator(int height, BlockState log, BlockState leaves) { + this.height = height; + this.log = log; + this.leaves = leaves; + } + + @Override + @Nullable + protected AbstractTreeFeature createTreeFeature(Random random) { + return new OakTreeFeature(DefaultFeatureConfig::deserialize, true, height, log, leaves, false); + } + } diff --git a/src/main/java/com/minelittlepony/util/AssetWalker.java b/src/main/java/com/minelittlepony/util/AssetWalker.java index dcd4fbc3..5f18d6ee 100644 --- a/src/main/java/com/minelittlepony/util/AssetWalker.java +++ b/src/main/java/com/minelittlepony/util/AssetWalker.java @@ -23,10 +23,12 @@ import com.google.gson.Gson; import com.google.gson.GsonBuilder; import com.google.gson.JsonObject; import com.google.gson.JsonParseException; -import com.minelittlepony.unicopia.util.crafting.CraftingManager; - import net.minecraft.util.Identifier; +/*** + * @deprecated Use Mojang's method + */ +@Deprecated public class AssetWalker { private static final Logger LOGGER = LogManager.getLogger(); @@ -60,7 +62,7 @@ public class AssetWalker { URI uri = url.toURI(); if ("file".equals(uri.getScheme())) { - readFiles(Paths.get(CraftingManager.class.getResource(loadLocation).toURI())); + readFiles(Paths.get(AssetWalker.class.getResource(loadLocation).toURI())); } else { if (!"jar".equals(uri.getScheme())) { LOGGER.error("Unsupported scheme " + uri + " trying to list all recipes"); diff --git a/src/main/java/com/minelittlepony/util/MagicalDamageSource.java b/src/main/java/com/minelittlepony/util/MagicalDamageSource.java index 7267df39..b601babd 100644 --- a/src/main/java/com/minelittlepony/util/MagicalDamageSource.java +++ b/src/main/java/com/minelittlepony/util/MagicalDamageSource.java @@ -18,6 +18,9 @@ public class MagicalDamageSource extends EntityDamageSource { public static final DamageSource FOOD_POISONING = new MundaneDamageSource("food_poisoning").setBypassesArmor(); public static final DamageSource ACID = new MundaneDamageSource("acid"); + public static final DamageSource ALICORN_AMULET = new MagicalDamageSource("alicorn_amulet").setUnblockable().setBypassesArmor(); + public static final DamageSource DARKNESS = new MagicalDamageSource("darkness"); + public static final DamageSource ZAP_APPLE = new MagicalDamageSource("zap"); public static DamageSource create(String type) { return new MagicalDamageSource(type); @@ -65,6 +68,19 @@ public class MagicalDamageSource extends EntityDamageSource { return new TranslatableText(basic, target.getDisplayName(), source.getDisplayName()); } + @Override + public MagicalDamageSource setUnblockable() { + super.setUnblockable(); + return this; + } + + + @Override + public MagicalDamageSource setBypassesArmor() { + super.setBypassesArmor(); + return this; + } + private static class MundaneDamageSource extends DamageSource { public MundaneDamageSource(String key) { diff --git a/src/main/java/com/minelittlepony/util/dummy/DummyClientPlayerEntity.java b/src/main/java/com/minelittlepony/util/dummy/DummyClientPlayerEntity.java new file mode 100644 index 00000000..85e28a81 --- /dev/null +++ b/src/main/java/com/minelittlepony/util/dummy/DummyClientPlayerEntity.java @@ -0,0 +1,81 @@ +package com.minelittlepony.util.dummy; + +import javax.annotation.Nonnull; + +import com.minelittlepony.unicopia.InteractionManager; +import com.minelittlepony.unicopia.entity.IOwned; +import com.mojang.authlib.GameProfile; + +import net.minecraft.client.MinecraftClient; +import net.minecraft.client.network.AbstractClientPlayerEntity; +import net.minecraft.client.network.ClientPlayNetworkHandler; +import net.minecraft.client.network.PlayerListEntry; +import net.minecraft.client.world.ClientWorld; +import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.item.ItemStack; +import net.minecraft.text.Text; +import net.minecraft.world.GameMode; + +public class DummyClientPlayerEntity extends AbstractClientPlayerEntity implements IOwned { + + private PlayerListEntry playerInfo; + + private PlayerEntity owner; + + public DummyClientPlayerEntity(ClientWorld world, GameProfile profile) { + super(world, profile); + } + + @Override + public boolean isSpectator() { + return getPlayerListEntry().getGameMode() == GameMode.SPECTATOR; + } + + @Override + public boolean isCreative() { + return getPlayerListEntry().getGameMode() == GameMode.CREATIVE; + } + + @Override + @Nonnull + protected PlayerListEntry getPlayerListEntry() { + if (playerInfo == null) { + ClientPlayNetworkHandler connection = MinecraftClient.getInstance().getNetworkHandler(); + + playerInfo = connection.getPlayerListEntry(getGameProfile().getId()); + + if (playerInfo == null) { + playerInfo = new PlayerListEntry(getGameProfile()); + } + } + + return playerInfo; + } + + @Override + protected void onEquipStack(ItemStack stack) { + /*noop*/ + } + + @Override + public boolean shouldRenderName() { + return !InteractionManager.instance().isClientPlayer(getOwner()); + } + + @Override + public PlayerEntity getOwner() { + return owner; + } + + @Override + public void setOwner(PlayerEntity owner) { + this.owner = owner; + } + + @Override + public Text getDisplayName() { + Text name = super.getDisplayName(); + name.getStyle().setItalic(true); + return name; + } +} diff --git a/src/main/java/com/minelittlepony/util/dummy/DummyPlayerEntity.java b/src/main/java/com/minelittlepony/util/dummy/DummyPlayerEntity.java new file mode 100644 index 00000000..13120bfb --- /dev/null +++ b/src/main/java/com/minelittlepony/util/dummy/DummyPlayerEntity.java @@ -0,0 +1,56 @@ +package com.minelittlepony.util.dummy; + +import com.minelittlepony.unicopia.InteractionManager; +import com.minelittlepony.unicopia.entity.IOwned; +import com.mojang.authlib.GameProfile; + +import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.item.ItemStack; +import net.minecraft.text.Text; +import net.minecraft.world.World; + +public class DummyPlayerEntity extends PlayerEntity implements IOwned { + + private PlayerEntity owner; + + public DummyPlayerEntity(World world, GameProfile profile) { + super(world, profile); + } + + @Override + protected void onEquipStack(ItemStack stack) { + /*noop*/ + } + + @Override + public PlayerEntity getOwner() { + return owner; + } + + @Override + public void setOwner(PlayerEntity owner) { + this.owner = owner; + } + + @Override + public boolean shouldRenderName() { + return !InteractionManager.instance().isClientPlayer(getOwner()); + } + + @Override + public Text getDisplayName() { + Text name = super.getDisplayName(); + name.getStyle().setItalic(true); + return name; + } + + @Override + public boolean isSpectator() { + return false; + } + + @Override + public boolean isCreative() { + return false; + } +} diff --git a/src/main/java/com/minelittlepony/util/dummy/DummyServerPlayerEntity.java b/src/main/java/com/minelittlepony/util/dummy/DummyServerPlayerEntity.java new file mode 100644 index 00000000..bd80ab0d --- /dev/null +++ b/src/main/java/com/minelittlepony/util/dummy/DummyServerPlayerEntity.java @@ -0,0 +1,48 @@ +package com.minelittlepony.util.dummy; + +import com.minelittlepony.unicopia.InteractionManager; +import com.minelittlepony.unicopia.entity.IOwned; +import com.mojang.authlib.GameProfile; + +import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.item.ItemStack; +import net.minecraft.server.network.ServerPlayerEntity; +import net.minecraft.server.network.ServerPlayerInteractionManager; +import net.minecraft.server.world.ServerWorld; +import net.minecraft.text.Text; + +public class DummyServerPlayerEntity extends ServerPlayerEntity implements IOwned { + + private PlayerEntity owner; + + public DummyServerPlayerEntity(ServerWorld world, GameProfile profile) { + super(world.getServer(), world, profile, new ServerPlayerInteractionManager(world)); + } + + @Override + protected void onEquipStack(ItemStack stack) { + /*noop*/ + } + + @Override + public PlayerEntity getOwner() { + return owner; + } + + @Override + public void setOwner(PlayerEntity owner) { + this.owner = owner; + } + + @Override + public boolean shouldRenderName() { + return !InteractionManager.instance().isClientPlayer(getOwner()); + } + + @Override + public Text getDisplayName() { + Text name = super.getDisplayName(); + name.getStyle().setItalic(true); + return name; + } +}