From 898e15a2211b4c844bfdc6c0d3a1ce36d6c6465d Mon Sep 17 00:00:00 2001 From: Vincent Lee Date: Sat, 22 Jun 2019 14:04:02 -0700 Subject: [PATCH] Misc fixes --- .../common/core/handler/PixieHandler.java | 4 +++- .../common/core/helper/MathHelper.java | 4 +--- .../botania/common/core/helper/Vector3.java | 2 +- .../botania/common/core/loot/LootHandler.java | 12 +++++++--- .../common/core/loot/TrueGuardianKiller.java | 11 +++++---- .../common/item/brew/ItemBrewBase.java | 2 +- .../armor/manasteel/ItemManasteelArmor.java | 2 +- .../armor/terrasteel/ItemTerrasteelArmor.java | 5 ++-- .../common/network/PacketBotaniaEffect.java | 6 ++--- .../botania/common/network/PacketHandler.java | 10 ++++---- .../common/world/MysticalFlowerConfig.java | 11 +++++++++ .../common/world/MysticalFlowerFeature.java | 9 ++++++- .../common/world/SkyblockWorldEvents.java | 24 +++++++++---------- 13 files changed, 64 insertions(+), 38 deletions(-) diff --git a/src/main/java/vazkii/botania/common/core/handler/PixieHandler.java b/src/main/java/vazkii/botania/common/core/handler/PixieHandler.java index c653d5eaa..97bdba39b 100644 --- a/src/main/java/vazkii/botania/common/core/handler/PixieHandler.java +++ b/src/main/java/vazkii/botania/common/core/handler/PixieHandler.java @@ -2,6 +2,7 @@ package vazkii.botania.common.core.handler; import net.minecraft.entity.LivingEntity; import net.minecraft.entity.LivingEntity; +import net.minecraft.entity.SpawnReason; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.potion.EffectInstance; @@ -70,7 +71,8 @@ public final class PixieHandler { dmg += 2; pixie.setProps((LivingEntity) event.getSource().getTrueSource(), player, 0, dmg); - pixie.onInitialSpawn(player.world.getDifficultyForLocation(new BlockPos(pixie)), null, null); + pixie.onInitialSpawn(player.world, player.world.getDifficultyForLocation(new BlockPos(pixie)), + SpawnReason.EVENT, null, null); player.world.addEntity(pixie); } } diff --git a/src/main/java/vazkii/botania/common/core/helper/MathHelper.java b/src/main/java/vazkii/botania/common/core/helper/MathHelper.java index 1dabef6ee..cae7cbdf6 100644 --- a/src/main/java/vazkii/botania/common/core/helper/MathHelper.java +++ b/src/main/java/vazkii/botania/common/core/helper/MathHelper.java @@ -33,9 +33,7 @@ public final class MathHelper { if(finalVector.mag() > 1) finalVector = finalVector.normalize(); - entity.motionX = finalVector.x * modifier; - entity.motionY = finalVector.y * modifier; - entity.motionZ = finalVector.z * modifier; + entity.setMotion(finalVector.multiply(modifier).toVec3D()); } private static final String[] ORDINAL_SUFFIXES = new String[]{ "th", "st", "nd", "rd", "th", "th", "th", "th", "th", "th" }; diff --git a/src/main/java/vazkii/botania/common/core/helper/Vector3.java b/src/main/java/vazkii/botania/common/core/helper/Vector3.java index 08407c473..298320018 100644 --- a/src/main/java/vazkii/botania/common/core/helper/Vector3.java +++ b/src/main/java/vazkii/botania/common/core/helper/Vector3.java @@ -55,7 +55,7 @@ public class Vector3 } public static Vector3 fromEntityCenter(Entity e) { - return new Vector3(e.posX, e.posY - e.getYOffset() + e.height / 2, e.posZ); + return new Vector3(e.posX, e.posY - e.getYOffset() + e.getHeight() / 2, e.posZ); } public static Vector3 fromTileEntity(TileEntity e) { diff --git a/src/main/java/vazkii/botania/common/core/loot/LootHandler.java b/src/main/java/vazkii/botania/common/core/loot/LootHandler.java index fa87a07c1..1e2271828 100644 --- a/src/main/java/vazkii/botania/common/core/loot/LootHandler.java +++ b/src/main/java/vazkii/botania/common/core/loot/LootHandler.java @@ -3,6 +3,7 @@ package vazkii.botania.common.core.loot; import net.minecraft.util.ResourceLocation; import net.minecraft.world.storage.loot.ILootGenerator; import net.minecraft.world.storage.loot.ILootGenerator; +import net.minecraft.world.storage.loot.LootEntry; import net.minecraft.world.storage.loot.TableLootEntry; import net.minecraft.world.storage.loot.LootPool; import net.minecraft.world.storage.loot.RandomValueRange; @@ -38,11 +39,16 @@ public final class LootHandler { } private static LootPool getInjectPool(String entryName) { - return new LootPool(new ILootGenerator[] { getInjectEntry(entryName, 1) }, new ILootCondition[0], new RandomValueRange(1), new RandomValueRange(0, 1), "botania_inject_pool"); + return LootPool.builder() + .addEntry(getInjectEntry(entryName, 1)) + // todo 1.14 can't set bonusRolls to [0, 1] + .build(); } - private static TableLootEntry getInjectEntry(String name, int weight) { - return new TableLootEntry(new ResourceLocation(LibMisc.MOD_ID, "inject/" + name), weight, 0, new ILootCondition[0], "botania_inject_entry"); + private static LootEntry.Builder getInjectEntry(String name, int weight) { + ResourceLocation table = new ResourceLocation(LibMisc.MOD_ID, "inject/" + name); + return TableLootEntry.func_216171_a(table) + .weight(weight); } } diff --git a/src/main/java/vazkii/botania/common/core/loot/TrueGuardianKiller.java b/src/main/java/vazkii/botania/common/core/loot/TrueGuardianKiller.java index 38de7b1e3..a5e962372 100644 --- a/src/main/java/vazkii/botania/common/core/loot/TrueGuardianKiller.java +++ b/src/main/java/vazkii/botania/common/core/loot/TrueGuardianKiller.java @@ -3,8 +3,10 @@ package vazkii.botania.common.core.loot; import com.google.gson.JsonDeserializationContext; import com.google.gson.JsonObject; import com.google.gson.JsonSerializationContext; +import net.minecraft.entity.Entity; import net.minecraft.util.ResourceLocation; import net.minecraft.world.storage.loot.LootContext; +import net.minecraft.world.storage.loot.LootParameters; import net.minecraft.world.storage.loot.conditions.ILootCondition; import net.minecraft.world.storage.loot.conditions.ILootCondition; import vazkii.botania.common.entity.EntityDoppleganger; @@ -16,12 +18,13 @@ import java.util.Random; public class TrueGuardianKiller implements ILootCondition { @Override - public boolean testCondition(@Nonnull Random rand, @Nonnull LootContext context) { - return context.getLootedEntity() instanceof EntityDoppleganger - && context.getKillerPlayer() == ((EntityDoppleganger) context.getLootedEntity()).trueKiller; + public boolean test(@Nonnull LootContext context) { + Entity victim = context.get(LootParameters.THIS_ENTITY); + return victim instanceof EntityDoppleganger + && context.get(LootParameters.KILLER_ENTITY) == ((EntityDoppleganger) victim).trueKiller; } - public static class Serializer extends ILootCondition.Serializer { + public static class Serializer extends ILootCondition.AbstractSerializer { public Serializer() { super(new ResourceLocation(LibMisc.MOD_ID, "true_guardian_killer"), TrueGuardianKiller.class); } diff --git a/src/main/java/vazkii/botania/common/item/brew/ItemBrewBase.java b/src/main/java/vazkii/botania/common/item/brew/ItemBrewBase.java index e056d1cd6..b2226881b 100644 --- a/src/main/java/vazkii/botania/common/item/brew/ItemBrewBase.java +++ b/src/main/java/vazkii/botania/common/item/brew/ItemBrewBase.java @@ -144,7 +144,7 @@ public class ItemBrewBase extends ItemMod implements IBrewItem { public void addInformation(ItemStack stack, World world, List list, ITooltipFlag flags) { Brew brew = getBrew(stack); for(EffectInstance effect : brew.getPotionEffects(stack)) { - TextFormatting format = effect.getPotion().isBadEffect() ? TextFormatting.RED : TextFormatting.GRAY; + TextFormatting format = !effect.getPotion().isBeneficial() ? TextFormatting.RED : TextFormatting.GRAY; ITextComponent cmp = new TranslationTextComponent(effect.getEffectName()); if(effect.getAmplifier() > 0) { cmp.appendText(" "); diff --git a/src/main/java/vazkii/botania/common/item/equipment/armor/manasteel/ItemManasteelArmor.java b/src/main/java/vazkii/botania/common/item/equipment/armor/manasteel/ItemManasteelArmor.java index 59359f886..bae8b67ac 100644 --- a/src/main/java/vazkii/botania/common/item/equipment/armor/manasteel/ItemManasteelArmor.java +++ b/src/main/java/vazkii/botania/common/item/equipment/armor/manasteel/ItemManasteelArmor.java @@ -142,7 +142,7 @@ public class ItemManasteelArmor extends ArmorItem implements IManaUsingItem, IPh @OnlyIn(Dist.CLIENT) @Override public void addInformation(ItemStack stack, World world, List list, ITooltipFlag flags) { - if(Screen.isShiftKeyDown()) + if(Screen.hasShiftDown()) addInformationAfterShift(stack, world, list, flags); else list.add(new TranslationTextComponent("botaniamisc.shiftinfo")); } diff --git a/src/main/java/vazkii/botania/common/item/equipment/armor/terrasteel/ItemTerrasteelArmor.java b/src/main/java/vazkii/botania/common/item/equipment/armor/terrasteel/ItemTerrasteelArmor.java index c09f2eff1..d20ca0f3b 100644 --- a/src/main/java/vazkii/botania/common/item/equipment/armor/terrasteel/ItemTerrasteelArmor.java +++ b/src/main/java/vazkii/botania/common/item/equipment/armor/terrasteel/ItemTerrasteelArmor.java @@ -60,9 +60,10 @@ public class ItemTerrasteelArmor extends ItemManasteelArmor { public Multimap getAttributeModifiers(@Nonnull EquipmentSlotType slot, ItemStack stack) { Multimap multimap = super.getAttributeModifiers(slot, stack); UUID uuid = new UUID((getTranslationKey(stack) + slot.toString()).hashCode(), 0); - if (slot == armorType) { + if (slot == getEquipmentSlot()) { int reduction = material.getDamageReductionAmount(slot); - multimap.put(SharedMonsterAttributes.KNOCKBACK_RESISTANCE.getName(), new AttributeModifier(uuid, "Terrasteel modifier " + type, (double) reduction / 20, 0)); + multimap.put(SharedMonsterAttributes.KNOCKBACK_RESISTANCE.getName(), + new AttributeModifier(uuid, "Terrasteel modifier " + type, (double) reduction / 20, AttributeModifier.Operation.ADDITION)); } return multimap; } diff --git a/src/main/java/vazkii/botania/common/network/PacketBotaniaEffect.java b/src/main/java/vazkii/botania/common/network/PacketBotaniaEffect.java index fe6bea876..6dd1dd848 100644 --- a/src/main/java/vazkii/botania/common/network/PacketBotaniaEffect.java +++ b/src/main/java/vazkii/botania/common/network/PacketBotaniaEffect.java @@ -114,8 +114,8 @@ public class PacketBotaniaEffect { double d2 = item.world.rand.nextGaussian() * m; double d3 = 10.0D; item.world.addParticle(ParticleTypes.POOF, - message.x + item.world.rand.nextFloat() * item.width * 2.0F - item.width - d0 * d3, message.y + item.world.rand.nextFloat() * item.height - d1 * d3, - message.z + item.world.rand.nextFloat() * item.width * 2.0F - item.width - d2 * d3, d0, d1, d2); + message.x + item.world.rand.nextFloat() * item.getWidth() * 2.0F - item.getWidth() - d0 * d3, message.y + item.world.rand.nextFloat() * item.getHeight() - d1 * d3, + message.z + item.world.rand.nextFloat() * item.getWidth() * 2.0F - item.getWidth() - d2 * d3, d0, d1, d2); } break; } @@ -259,7 +259,7 @@ public class PacketBotaniaEffect { double z = target.posZ; for(int i = 0; i < 50; i++) - Botania.proxy.sparkleFX(x + Math.random() * target.width, y + Math.random() * target.height, z + Math.random() * target.width, 1F, 1F, 0.25F, 1F, 3); + Botania.proxy.sparkleFX(x + Math.random() * target.getWidth(), y + Math.random() * target.getHeight(), z + Math.random() * target.getWidth(), 1F, 1F, 0.25F, 1F, 3); break; } } diff --git a/src/main/java/vazkii/botania/common/network/PacketHandler.java b/src/main/java/vazkii/botania/common/network/PacketHandler.java index 0bcb8b315..2e1e460ef 100644 --- a/src/main/java/vazkii/botania/common/network/PacketHandler.java +++ b/src/main/java/vazkii/botania/common/network/PacketHandler.java @@ -11,6 +11,7 @@ import net.minecraft.world.World; import net.minecraft.world.ServerWorld; import net.minecraftforge.fml.network.NetworkDirection; import net.minecraftforge.fml.network.NetworkRegistry; +import net.minecraftforge.fml.network.PacketDistributor; import net.minecraftforge.fml.network.simple.SimpleChannel; import vazkii.botania.common.lib.LibMisc; @@ -39,12 +40,9 @@ public final class PacketHandler { if(world instanceof ServerWorld) { ServerWorld ws = (ServerWorld) world; - for (PlayerEntity player : ws.playerEntities) { - ServerPlayerEntity playerMP = (ServerPlayerEntity) player; - - if (playerMP.getDistanceSq(pos) < 64 * 64 - && ws.getPlayerChunkMap().isPlayerWatchingChunk(playerMP, pos.getX() >> 4, pos.getZ() >> 4)) { - HANDLER.sendTo(toSend, playerMP.connection.getNetworkManager(), NetworkDirection.PLAY_TO_CLIENT); + for (ServerPlayerEntity playerMP : ws.getPlayers()) { + if (playerMP.getDistanceSq(pos.getX(), pos.getY(), pos.getZ()) < 64 * 64) { + HANDLER.send(PacketDistributor.TRACKING_CHUNK.with(() -> world.getChunkAt(pos)), toSend); } } diff --git a/src/main/java/vazkii/botania/common/world/MysticalFlowerConfig.java b/src/main/java/vazkii/botania/common/world/MysticalFlowerConfig.java index c0787c9a8..231082b8d 100644 --- a/src/main/java/vazkii/botania/common/world/MysticalFlowerConfig.java +++ b/src/main/java/vazkii/botania/common/world/MysticalFlowerConfig.java @@ -1,8 +1,12 @@ package vazkii.botania.common.world; +import com.mojang.datafixers.Dynamic; +import com.mojang.datafixers.types.DynamicOps; import net.minecraft.world.gen.feature.IFeatureConfig; import vazkii.botania.common.core.handler.ConfigHandler; +import javax.annotation.Nonnull; + public class MysticalFlowerConfig implements IFeatureConfig { public int getPatchSize() { return ConfigHandler.COMMON.flowerPatchSize.get(); @@ -27,4 +31,11 @@ public class MysticalFlowerConfig implements IFeatureConfig { public int getMushroomPatchSize() { return ConfigHandler.COMMON.mushroomQuantity.get(); } + + @Nonnull + @Override + public Dynamic serialize(@Nonnull DynamicOps ops) { + // todo 1.14 + return new Dynamic<>(ops); + } } diff --git a/src/main/java/vazkii/botania/common/world/MysticalFlowerFeature.java b/src/main/java/vazkii/botania/common/world/MysticalFlowerFeature.java index fc5212ee0..25019f8ea 100644 --- a/src/main/java/vazkii/botania/common/world/MysticalFlowerFeature.java +++ b/src/main/java/vazkii/botania/common/world/MysticalFlowerFeature.java @@ -1,5 +1,6 @@ package vazkii.botania.common.world; +import com.mojang.datafixers.Dynamic; import net.minecraft.block.Block; import net.minecraft.block.DoublePlantBlock; import net.minecraft.block.BlockState; @@ -19,8 +20,13 @@ import vazkii.botania.common.block.ModBlocks; import javax.annotation.Nonnull; import java.util.Random; +import java.util.function.Function; public class MysticalFlowerFeature extends Feature { + public MysticalFlowerFeature(Function, ? extends MysticalFlowerConfig> configFactoryIn) { + super(configFactoryIn); + } + @Override public boolean place(@Nonnull IWorld world, @Nonnull ChunkGenerator generator, @Nonnull Random rand, @Nonnull BlockPos pos, @Nonnull MysticalFlowerConfig config) { boolean flowers = true; @@ -49,7 +55,8 @@ public class MysticalFlowerFeature extends Feature { BlockPos pos2 = new BlockPos(x1, y1, z1); if(world.isAirBlock(pos2) && (!world.getDimension().isNether() || y1 < 127) && flower.isValidPosition(world, pos2)) { world.setBlockState(pos2, flower, 2); - if(rand.nextDouble() < config.getTallChance() && ((BlockModFlower) flower).canGrow(world, pos2, world.getBlockState(pos2), false)) { + if(rand.nextDouble() < config.getTallChance() + && ((BlockModFlower) flower.getBlock()).canGrow(world, pos2, world.getBlockState(pos2), false)) { Block block = ModBlocks.getDoubleFlower(color); if(block instanceof DoublePlantBlock) { ((DoublePlantBlock) block).placeAt(world, pos2, 3); diff --git a/src/main/java/vazkii/botania/common/world/SkyblockWorldEvents.java b/src/main/java/vazkii/botania/common/world/SkyblockWorldEvents.java index 1f41a7a95..3fbfd37a7 100644 --- a/src/main/java/vazkii/botania/common/world/SkyblockWorldEvents.java +++ b/src/main/java/vazkii/botania/common/world/SkyblockWorldEvents.java @@ -33,6 +33,7 @@ import net.minecraft.util.ActionResultType; import net.minecraft.util.ResourceLocation; import net.minecraft.util.SoundCategory; import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.BlockRayTraceResult; import net.minecraft.util.math.RayTraceResult; import net.minecraft.world.World; import net.minecraft.world.dimension.DimensionType; @@ -109,20 +110,19 @@ public final class SkyblockWorldEvents { } } else if(!equipped.isEmpty() && equipped.getItem() == Items.BOWL) { RayTraceResult rtr = ToolCommons.raytraceFromEntity(event.getWorld(), event.getEntityPlayer(), true, 4.5F); - if(rtr != null) { - if (rtr.type == RayTraceResult.Type.BLOCK) { - if(event.getWorld().getBlockState(rtr.getBlockPos()).getMaterial() == Material.WATER) { - if(!event.getWorld().isRemote) { - equipped.shrink(1); + if(rtr.getType() == RayTraceResult.Type.BLOCK) { + BlockPos pos = ((BlockRayTraceResult) rtr).getPos(); + if(event.getWorld().getBlockState(pos).getMaterial() == Material.WATER) { + if(!event.getWorld().isRemote) { + equipped.shrink(1); - if(equipped.isEmpty()) - event.getEntityPlayer().setHeldItem(event.getHand(), new ItemStack(ModItems.waterBowl)); - else ItemHandlerHelper.giveItemToPlayer(event.getEntityPlayer(), new ItemStack(ModItems.waterBowl)); - } - - event.setCanceled(true); - event.setCancellationResult(ActionResultType.SUCCESS); + if(equipped.isEmpty()) + event.getEntityPlayer().setHeldItem(event.getHand(), new ItemStack(ModItems.waterBowl)); + else ItemHandlerHelper.giveItemToPlayer(event.getEntityPlayer(), new ItemStack(ModItems.waterBowl)); } + + event.setCanceled(true); + event.setCancellationResult(ActionResultType.SUCCESS); } } }