Merge 1.14, and clean up some unused AT entries.

This commit is contained in:
Vincent Lee committed 2020-04-05 00:32:21 -05:00
commit 2eb14c45eb
23 files changed
+211 -51

No files matched your search

@@ -239,7 +239,7 @@ public class TileEntitySpecialFlower extends TileEntity implements ITickableTile
/**
* Called when this sub tile is placed in the world (by an entity).
*/
public void onBlockPlacedBy(World world, BlockPos pos, BlockState state, LivingEntity entity, ItemStack stack) {}
public void onBlockPlacedBy(World world, BlockPos pos, BlockState state, @Nullable LivingEntity entity, ItemStack stack) {}
/**
* Called when a player right clicks this sub tile.
@@ -36,6 +36,7 @@ import vazkii.botania.api.wand.IWandable;
import vazkii.botania.common.block.tile.TileAnimatedTorch;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
public class BlockAnimatedTorch extends BlockMod implements IWandable, IManaTrigger, IHourglassTrigger, IWandHUD {
@@ -56,7 +57,7 @@ public class BlockAnimatedTorch extends BlockMod implements IWandable, IManaTrig
}
@Override
public void onBlockPlacedBy(World world, BlockPos pos, BlockState state, LivingEntity entity, ItemStack stack) {
public void onBlockPlacedBy(World world, BlockPos pos, BlockState state, @Nullable LivingEntity entity, ItemStack stack) {
((TileAnimatedTorch) world.getTileEntity(pos)).onPlace(entity);
}
@@ -28,7 +28,9 @@ import net.minecraft.world.IBlockReader;
import net.minecraft.world.World;
import net.minecraft.world.server.ServerWorld;
import vazkii.botania.client.fx.WispParticleData;
import vazkii.botania.common.block.tile.TileCocoon;
import vazkii.botania.common.item.ModItems;
import javax.annotation.Nonnull;
@@ -75,20 +77,27 @@ public class BlockCocoon extends BlockMod {
TileCocoon cocoon = (TileCocoon) world.getTileEntity(pos);
Item item = stack.getItem();
if (cocoon != null && (item == Items.EMERALD || item == Items.CHORUS_FRUIT)) {
if (!world.isRemote) {
if (item == Items.EMERALD && cocoon.emeraldsGiven < TileCocoon.MAX_EMERALDS) {
if (!creative) {
if(cocoon != null && (item == Items.EMERALD || item == Items.CHORUS_FRUIT || item == ModItems.lifeEssence)) {
if(!world.isRemote) {
if(item == Items.EMERALD && cocoon.emeraldsGiven < TileCocoon.MAX_EMERALDS) {
if(!creative) {
stack.shrink(1);
}
cocoon.emeraldsGiven++;
((ServerWorld) world).spawnParticle(ParticleTypes.HAPPY_VILLAGER, pos.getX() + 0.5, pos.getY() + 1, pos.getZ() + 0.5, 1, 0, 0, 0, 0.5);
} else if (item == Items.CHORUS_FRUIT && cocoon.chorusFruitGiven < TileCocoon.MAX_CHORUS_FRUITS) {
if (!creative) {
((ServerWorld) world).spawnParticle(ParticleTypes.HAPPY_VILLAGER, pos.getX() + 0.5, pos.getY() + 1, pos.getZ() + 0.5, 1, 0.1, 0.05, 0.1, 0.5);
} else if(item == Items.CHORUS_FRUIT && cocoon.chorusFruitGiven < TileCocoon.MAX_CHORUS_FRUITS) {
if(!creative) {
stack.shrink(1);
}
cocoon.chorusFruitGiven++;
((ServerWorld) world).spawnParticle(ParticleTypes.PORTAL, pos.getX() + 0.5, pos.getY(), pos.getZ() + 0.5, 32, 0, 0, 0, 0.5);
} else if (item == ModItems.lifeEssence && !cocoon.gaiaSpiritGiven) {
if(!creative) {
stack.shrink(1);
}
cocoon.forceRare();
WispParticleData data = WispParticleData.wisp(0.6F, 0F, 1F, 0F);
((ServerWorld) world).spawnParticle(data, pos.getX() + 0.5, pos.getY() + 0.7, pos.getZ() + 0.5, 8, 0.1, 0.1, 0.1, 0.04);
}
}
@@ -33,7 +33,7 @@ import vazkii.botania.api.wand.IWandable;
import vazkii.botania.common.block.decor.BlockFloatingFlower;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.List;
import java.util.Random;
import java.util.function.Supplier;
@@ -100,7 +100,7 @@ public class BlockFloatingSpecialFlower extends BlockFloatingFlower implements I
}
@Override
public void onBlockPlacedBy(World world, BlockPos pos, BlockState state, LivingEntity entity, ItemStack stack) {
public void onBlockPlacedBy(World world, BlockPos pos, BlockState state, @Nullable LivingEntity entity, ItemStack stack) {
((TileEntitySpecialFlower) world.getTileEntity(pos)).onBlockPlacedBy(world, pos, state, entity, stack);
}
@@ -45,6 +45,7 @@ import net.minecraftforge.fml.server.ServerLifecycleHooks;
import vazkii.botania.api.wand.IWandable;
import vazkii.botania.common.core.handler.ModSounds;
import vazkii.botania.common.item.ItemTwigWand;
import vazkii.botania.common.item.lens.LensPiston;
import vazkii.botania.common.network.PacketBotaniaEffect;
import vazkii.botania.common.network.PacketHandler;
@@ -237,7 +238,7 @@ public class BlockPistonRelay extends BlockMod implements IWandable {
Material destMat = world.getBlockState(destPos.offset(dir)).getMaterial();
if (world.isAirBlock(destPos.offset(dir)) || destMat.isReplaceable()) {
world.setBlockState(destPos, Blocks.AIR.getDefaultState());
world.setBlockState(destPos.offset(dir), srcState);
world.setBlockState(destPos.offset(dir), LensPiston.unWaterlog(srcState));
data.mapping.put(s.getPos(), destPos.offset(dir));
}
}
@@ -37,7 +37,7 @@ import vazkii.botania.api.wand.IWandHUD;
import vazkii.botania.api.wand.IWandable;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.List;
import java.util.function.Supplier;
@@ -131,7 +131,7 @@ public class BlockSpecialFlower extends FlowerBlock implements IWandable, IWandH
}
@Override
public void onBlockPlacedBy(World world, BlockPos pos, BlockState state, LivingEntity entity, ItemStack stack) {
public void onBlockPlacedBy(World world, BlockPos pos, BlockState state, @Nullable LivingEntity entity, ItemStack stack) {
((TileEntitySpecialFlower) world.getTileEntity(pos)).onBlockPlacedBy(world, pos, state, entity, stack);
}
@@ -37,6 +37,7 @@ import vazkii.botania.common.block.tile.TileTinyPotato;
import vazkii.botania.common.core.helper.InventoryHelper;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
public class BlockTinyPotato extends BlockMod {
@@ -87,7 +88,7 @@ public class BlockTinyPotato extends BlockMod {
}
@Override
public void onBlockPlacedBy(World world, BlockPos pos, BlockState state, LivingEntity entity, ItemStack stack) {
public void onBlockPlacedBy(World world, BlockPos pos, BlockState state, @Nullable LivingEntity living, ItemStack stack) {
if (stack.hasDisplayName()) {
((TileTinyPotato) world.getTileEntity(pos)).name = stack.getDisplayName();
}
@@ -44,6 +44,7 @@ import vazkii.botania.common.core.helper.InventoryHelper;
import vazkii.botania.common.item.ModItems;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.List;
@@ -94,8 +95,8 @@ public class BlockSpreader extends BlockMod implements IWandable, IWandHUD, IWir
}
@Override
public void onBlockPlacedBy(World world, BlockPos pos, BlockState state, LivingEntity placer, ItemStack stack) {
Direction orientation = Direction.getFacingDirections(placer)[0].getOpposite();
public void onBlockPlacedBy(World world, BlockPos pos, BlockState state, @Nullable LivingEntity placer, ItemStack stack) {
Direction orientation = placer == null ? Direction.WEST : Direction.getFacingDirections(placer)[0].getOpposite();
TileSpreader spreader = (TileSpreader) world.getTileEntity(pos);
switch (orientation) {
@@ -113,7 +114,7 @@ public class BlockSpreader extends BlockMod implements IWandable, IWandHUD, IWir
break;
case WEST:
break;
default:
case EAST:
spreader.rotationX = 180F;
break;
}
@@ -149,6 +149,11 @@ public class BergamuteEventHandler {
return compose.getZ();
}
@Override
public boolean canBeSilent() {
return compose.canBeSilent();
}
@Nonnull
@Override
public AttenuationType getAttenuationType() {
@@ -27,6 +27,7 @@ import vazkii.botania.common.block.ModBlocks;
import vazkii.botania.common.lib.LibBlockNames;
import vazkii.botania.common.lib.LibMisc;
import javax.annotation.Nullable;
import java.util.Arrays;
public class TileAnimatedTorch extends TileMod implements ITickableTileEntity {
@@ -76,8 +77,8 @@ public class TileAnimatedTorch extends TileMod implements ITickableTileEntity {
}
}
public void onPlace(LivingEntity entity) {
if (entity != null) {
public void onPlace(@Nullable LivingEntity entity) {
if(entity != null) {
side = Arrays.asList(SIDES).indexOf(entity.getHorizontalFacing().getOpposite());
}
world.notifyNeighborsOfStateChange(getPos().offset(SIDES[side].getOpposite()), getBlockState().getBlock());
@@ -37,6 +37,8 @@ public class TileCocoon extends TileMod implements ITickableTileEntity {
private static final String TAG_TIME_PASSED = "timePassed";
private static final String TAG_EMERALDS_GIVEN = "emeraldsGiven";
private static final String TAG_CHORUS_FRUIT_GIVEN = "chorusFruitGiven";
private static final String TAG_GAIA_SPIRIT_GIVEN = "gaiaSpiritGiven";
private static final List<EntityType<? extends MobEntity>> SPECIALS = ImmutableList.of(
EntityType.HORSE, EntityType.DONKEY, EntityType.WOLF, EntityType.OCELOT,
EntityType.CAT, EntityType.PARROT, EntityType.LLAMA, EntityType.FOX,
@@ -57,6 +59,7 @@ public class TileCocoon extends TileMod implements ITickableTileEntity {
public int timePassed;
public int emeraldsGiven;
public int chorusFruitGiven;
public boolean gaiaSpiritGiven;
public TileCocoon() {
super(TYPE);
@@ -77,6 +80,7 @@ public class TileCocoon extends TileMod implements ITickableTileEntity {
MobEntity entity = null;
BlockPos placePos = pos;
float rareChance = gaiaSpiritGiven ? 1F : SPECIAL_CHANCE;
float villagerChance = Math.min(1F, (float) emeraldsGiven / (float) MAX_EMERALDS);
float shulkerChance = Math.min(1F, (float) chorusFruitGiven / (float) MAX_CHORUS_FRUITS);
@@ -103,13 +107,13 @@ public class TileCocoon extends TileMod implements ITickableTileEntity {
entity = villager;
} else if (!validWater.isEmpty()) {
placePos = validWater.get(world.rand.nextInt(validWater.size()));
if (Math.random() < SPECIAL_CHANCE) {
if (Math.random() < rareChance) {
entity = EntityType.DOLPHIN.create(world);
} else {
entity = AQUATIC.get(world.rand.nextInt(AQUATIC.size())).create(world);
}
} else {
if (Math.random() < SPECIAL_CHANCE) {
if(Math.random() < rareChance) {
entity = SPECIALS.get(world.rand.nextInt(SPECIALS.size())).create(world);
} else {
EntityType<? extends MobEntity> type = NORMALS.get(world.rand.nextInt(NORMALS.size()));
@@ -133,11 +137,17 @@ public class TileCocoon extends TileMod implements ITickableTileEntity {
}
}
public void forceRare() {
gaiaSpiritGiven = true;
timePassed = Math.min(timePassed, TOTAL_TIME / 3);
}
@Override
public void writePacketNBT(CompoundNBT cmp) {
cmp.putInt(TAG_TIME_PASSED, timePassed);
cmp.putInt(TAG_EMERALDS_GIVEN, emeraldsGiven);
cmp.putInt(TAG_CHORUS_FRUIT_GIVEN, chorusFruitGiven);
cmp.putBoolean(TAG_GAIA_SPIRIT_GIVEN, gaiaSpiritGiven);
}
@Override
@@ -145,6 +155,6 @@ public class TileCocoon extends TileMod implements ITickableTileEntity {
timePassed = cmp.getInt(TAG_TIME_PASSED);
emeraldsGiven = cmp.getInt(TAG_EMERALDS_GIVEN);
chorusFruitGiven = cmp.getInt(TAG_CHORUS_FRUIT_GIVEN);
gaiaSpiritGiven = cmp.getBoolean(TAG_GAIA_SPIRIT_GIVEN);
}
}
@@ -8,17 +8,20 @@
*/
package vazkii.botania.common.core.helper;
import com.mojang.datafixers.util.Pair;
import net.minecraft.advancements.Advancement;
import net.minecraft.advancements.AdvancementManager;
import net.minecraft.advancements.PlayerAdvancements;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.ServerPlayerEntity;
import net.minecraft.item.BlockItemUseContext;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.item.ItemUseContext;
import net.minecraft.util.ActionResultType;
import net.minecraft.util.Hand;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.BlockRayTraceResult;
import java.util.function.Predicate;
@@ -115,13 +118,19 @@ public final class PlayerHelper {
}
}
public static ActionResultType substituteUse(ItemUseContext ctx, ItemStack toUse) {
return substituteUseTrackPos(ctx, toUse).getFirst();
}
/**
* Temporarily swap <code>toUse</code> into the hand of the player, use it, then swap it back out.
* This is to ensure that any code in mods' onItemUse that relies on player.getHeldItem(ctx.hand) == ctx.stack
* will work as intended.
* Properly handles null players, as long as the Item's onItemUse also handles them.
* @return The usage result, as well as a properly offset block position pointing at where the block was placed
* (if the item was a BlockItem)
*/
public static ActionResultType substituteUse(ItemUseContext ctx, ItemStack toUse) {
public static Pair<ActionResultType, BlockPos> substituteUseTrackPos(ItemUseContext ctx, ItemStack toUse) {
ItemStack save = ItemStack.EMPTY;
BlockRayTraceResult hit = new BlockRayTraceResult(ctx.getHitVec(), ctx.getFace(), ctx.getPos(), ctx.isInside());
ItemUseContext newCtx;
@@ -135,13 +144,15 @@ public final class PlayerHelper {
newCtx = new ItemUseContext(ctx.getWorld(), null, ctx.getHand(), toUse, hit);
}
BlockPos finalPos = new BlockItemUseContext(newCtx).getPos();
ActionResultType result = toUse.onItemUse(newCtx);
if (ctx.getPlayer() != null) {
ctx.getPlayer().setHeldItem(ctx.getHand(), save);
}
return result;
return Pair.of(result, finalPos);
}
private PlayerHelper() {}
@@ -598,7 +598,7 @@ public class EntityDoppleganger extends MobEntity implements IEntityAdditionalSp
private void clearPotions(PlayerEntity player) {
List<Effect> potionsToRemove = player.getActivePotionEffects().stream()
.filter(effect -> effect.getDuration() < 160 && effect.isAmbient() && effect.getPotion().type != EffectType.HARMFUL)
.filter(effect -> effect.getDuration() < 160 && effect.isAmbient() && effect.getPotion().getEffectType() != EffectType.HARMFUL)
.map(EffectInstance::getPotion)
.distinct()
.collect(Collectors.toList());
@@ -23,6 +23,7 @@ import net.minecraft.nbt.CompoundNBT;
import net.minecraft.nbt.NBTUtil;
import net.minecraft.particles.BlockParticleData;
import net.minecraft.particles.ParticleTypes;
import net.minecraft.state.properties.BlockStateProperties;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.ActionResultType;
import net.minecraft.util.NonNullList;
@@ -156,7 +157,8 @@ public class ItemLaputaShard extends Item implements ILensEffect, ITinyPlanetExc
TileEntity newTile = block.createTileEntity(state, world);
world.setTileEntity(pos_, newTile);
}
world.destroyBlock(pos_, false);
world.playEvent(2001, pos_, Block.getStateId(state));
world.setBlockState(pos_, Blocks.AIR.getDefaultState());
ItemStack copyLens = new ItemStack(this);
copyLens.getOrCreateTag().putInt(TAG_LEVEL, getShardLevel(shard));
@@ -260,6 +262,10 @@ public class ItemLaputaShard extends Item implements ILensEffect, ITinyPlanetExc
state = NBTUtil.readBlockState(lens.getTag().getCompound(TAG_STATE));
}
if (entity.world.getDimension().doesWaterVaporize() && state.has(BlockStateProperties.WATERLOGGED)) {
state = state.with(BlockStateProperties.WATERLOGGED, false);
}
TileEntity tile = null;
CompoundNBT tilecmp = ItemNBTHelper.getCompound(lens, TAG_TILE, false);
if (tilecmp.contains("id")) {
@@ -8,6 +8,7 @@
*/
package vazkii.botania.common.item;
import com.mojang.datafixers.util.Pair;
import net.minecraft.block.Blocks;
import net.minecraft.client.util.ITooltipFlag;
import net.minecraft.entity.EntityType;
@@ -17,6 +18,7 @@ import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.item.ItemUseContext;
import net.minecraft.nbt.CompoundNBT;
import net.minecraft.tileentity.MobSpawnerTileEntity;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.ActionResultType;
import net.minecraft.util.ResourceLocation;
@@ -90,12 +92,11 @@ public class ItemSpawnerMover extends Item {
private ActionResultType placeSpawner(ItemUseContext ctx) {
ItemStack useStack = new ItemStack(Blocks.SPAWNER);
useStack.getOrCreateTag().put("BlockEntityTag", ctx.getItem().getChildTag(TAG_SPAWNER));
ActionResultType res = PlayerHelper.substituteUse(ctx, useStack);
Pair<ActionResultType, BlockPos> res = PlayerHelper.substituteUseTrackPos(ctx, useStack);
if (res == ActionResultType.SUCCESS) {
if(res.getFirst() == ActionResultType.SUCCESS) {
World world = ctx.getWorld();
BlockPos pos = ctx.getPos();
BlockPos pos = res.getSecond();
ItemStack mover = ctx.getItem();
if (!world.isRemote) {
@@ -103,6 +104,15 @@ public class ItemSpawnerMover extends Item {
ctx.getPlayer().sendBreakAnimation(ctx.getHand());
}
mover.shrink(1);
TileEntity te = world.getTileEntity(pos);
if (te instanceof MobSpawnerTileEntity) {
CompoundNBT spawnerTag = ctx.getItem().getChildTag(TAG_SPAWNER).copy();
spawnerTag.putInt("x", pos.getX());
spawnerTag.putInt("y", pos.getY());
spawnerTag.putInt("z", pos.getZ());
te.read(spawnerTag);
}
} else {
for (int i = 0; i < 100; i++) {
SparkleParticleData data = SparkleParticleData.sparkle(0.45F + 0.2F * (float) Math.random(), (float) Math.random(), (float) Math.random(), (float) Math.random(), 6);
@@ -111,7 +121,7 @@ public class ItemSpawnerMover extends Item {
}
}
return res;
return res.getFirst();
}
private boolean captureSpawner(ItemUseContext ctx) {
@@ -8,11 +8,13 @@
*/
package vazkii.botania.common.item.lens;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
import net.minecraft.block.material.PushReaction;
import net.minecraft.entity.projectile.ThrowableEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.state.properties.BlockStateProperties;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.BlockRayTraceResult;
@@ -39,8 +41,9 @@ public class LensPiston extends Lens {
if (state.getPushReaction() == PushReaction.NORMAL && state.getBlock() != Blocks.OBSIDIAN
&& state.getBlockHardness(entity.world, pos_) >= 0 && tile == null) {
entity.world.destroyBlock(rtr.getPos(), false);
entity.world.setBlockState(pos_, state);
entity.world.playEvent(2001, rtr.getPos(), Block.getStateId(state));
entity.world.setBlockState(rtr.getPos(), Blocks.AIR.getDefaultState());
entity.world.setBlockState(pos_, unWaterlog(state));
}
}
}
@@ -49,4 +52,12 @@ public class LensPiston extends Lens {
return dead;
}
public static BlockState unWaterlog(BlockState state) {
if (state.has(BlockStateProperties.WATERLOGGED)) {
return state.with(BlockStateProperties.WATERLOGGED, false);
} else {
return state;
}
}
}