mirror of
https://github.com/GTNewHorizons/Botania.git
synced 2026-11-26 23:13:09 +00:00
Another pass through items/entities
This commit is contained in:
1 parent
4ad7e675eb
commit
95fc132f9f
74 files changed
+642
-708
No files matched your search
@@ -14,12 +14,13 @@ import net.minecraft.block.Block;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.client.resources.I18n;
|
||||
import net.minecraft.client.util.ITooltipFlag;
|
||||
import net.minecraft.entity.EntityList;
|
||||
import net.minecraft.entity.EntityType;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.item.BlockItemUseContext;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.ItemUseContext;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.tileentity.TileEntityMobSpawner;
|
||||
@@ -41,6 +42,7 @@ import vazkii.botania.common.advancements.UseItemSuccessTrigger;
|
||||
import vazkii.botania.common.lib.LibItemNames;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.List;
|
||||
|
||||
public class ItemSpawnerMover extends ItemMod {
|
||||
@@ -54,7 +56,8 @@ public class ItemSpawnerMover extends ItemMod {
|
||||
addPropertyOverride(new ResourceLocation("botania", "full"), (stack, worldIn, entityIn) -> hasData(stack) ? 1 : 0);
|
||||
}
|
||||
|
||||
public static NBTTagCompound getSpawnerTag(ItemStack stack) {
|
||||
@Nullable
|
||||
private static NBTTagCompound getSpawnerTag(ItemStack stack) {
|
||||
NBTTagCompound tag = stack.getTag();
|
||||
if(tag != null && tag.contains(TAG_SPAWNER)) {
|
||||
return tag.getCompound(TAG_SPAWNER);
|
||||
@@ -63,6 +66,7 @@ public class ItemSpawnerMover extends ItemMod {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static ResourceLocation getEntityId(ItemStack stack) {
|
||||
NBTTagCompound tag = getSpawnerTag(stack);
|
||||
if(tag != null && tag.contains(TAG_SPAWN_DATA)) {
|
||||
@@ -75,7 +79,7 @@ public class ItemSpawnerMover extends ItemMod {
|
||||
return null;
|
||||
}
|
||||
|
||||
public static boolean hasData(ItemStack stack) {
|
||||
private static boolean hasData(ItemStack stack) {
|
||||
return getEntityId(stack) != null;
|
||||
}
|
||||
|
||||
@@ -84,7 +88,7 @@ public class ItemSpawnerMover extends ItemMod {
|
||||
public void addInformation(ItemStack stack, World world, List<ITextComponent> infoList, ITooltipFlag flags) {
|
||||
ResourceLocation id = getEntityId(stack);
|
||||
if (id != null) {
|
||||
EntityType<?> type = ForgeRegistries.ENTITIES.getValue();
|
||||
EntityType<?> type = ForgeRegistries.ENTITIES.getValue(id);
|
||||
if (type != null) {
|
||||
infoList.add(type.func_212546_e());
|
||||
}
|
||||
@@ -93,84 +97,75 @@ public class ItemSpawnerMover extends ItemMod {
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public EnumActionResult onItemUse(EntityPlayer player, World world, BlockPos pos, EnumHand hand, EnumFacing side, float xOffset, float yOffset, float zOffset) {
|
||||
ItemStack itemstack = player.getHeldItem(hand);
|
||||
if(getEntityId(itemstack) == null) {
|
||||
if(world.getBlockState(pos).getBlock() == Blocks.SPAWNER) {
|
||||
if(!world.isRemote) {
|
||||
TileEntity te = world.getTileEntity(pos);
|
||||
NBTTagCompound tag = new NBTTagCompound();
|
||||
tag.put(TAG_SPAWNER, te.write(new NBTTagCompound()));
|
||||
player.getCooldownTracker().setCooldown(this, 20);
|
||||
itemstack.setTag(tag);
|
||||
world.destroyBlock(pos, false);
|
||||
UseItemSuccessTrigger.INSTANCE.trigger((EntityPlayerMP) player, itemstack, (WorldServer) world, pos.getX(), pos.getY(), pos.getZ());
|
||||
player.renderBrokenItemStack(itemstack);
|
||||
} else {
|
||||
for(int i = 0; i < 50; i++) {
|
||||
float red = (float) Math.random();
|
||||
float green = (float) Math.random();
|
||||
float blue = (float) Math.random();
|
||||
Botania.proxy.wispFX(pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5, red, green, blue, (float) Math.random() * 0.1F + 0.05F, (float) (Math.random() - 0.5F) * 0.15F, (float) (Math.random() - 0.5F) * 0.15F, (float) (Math.random() - 0.5F) * 0.15F);
|
||||
}
|
||||
}
|
||||
return EnumActionResult.SUCCESS;
|
||||
} else return EnumActionResult.PASS;
|
||||
public EnumActionResult onItemUse(ItemUseContext ctx) {
|
||||
if(getEntityId(ctx.getItem()) == null) {
|
||||
return captureSpawner(ctx) ? EnumActionResult.SUCCESS : EnumActionResult.PASS;
|
||||
} else {
|
||||
return placeBlock(itemstack, player, world, pos, side, xOffset, yOffset, zOffset) ? EnumActionResult.SUCCESS : EnumActionResult.PASS;
|
||||
return placeSpawner(ctx);
|
||||
}
|
||||
}
|
||||
|
||||
// Adapted from ItemBlock.onItemUse
|
||||
private boolean placeBlock(ItemStack itemstack, EntityPlayer player, World world, BlockPos pos, EnumFacing side, float xOffset, float yOffset, float zOffset) {
|
||||
IBlockState iblockstate = world.getBlockState(pos);
|
||||
Block block = iblockstate.getBlock();
|
||||
private EnumActionResult placeSpawner(ItemUseContext ctx) {
|
||||
ItemStack spawner = new ItemStack(Blocks.SPAWNER);
|
||||
ItemUseContext placeCtx = new BlockItemUseContext(ctx.getWorld(), ctx.getPlayer(), spawner, ctx.getPos(), ctx.getFace(), ctx.getHitX(), ctx.getHitY(), ctx.getHitZ());
|
||||
EnumActionResult res = spawner.onItemUse(placeCtx);
|
||||
|
||||
if(!block.isReplaceable(world, pos)) {
|
||||
pos = pos.offset(side);
|
||||
}
|
||||
if(res == EnumActionResult.SUCCESS) {
|
||||
World world = ctx.getWorld();
|
||||
BlockPos pos = ctx.getPos();
|
||||
ItemStack mover = ctx.getItem();
|
||||
|
||||
if(itemstack.isEmpty()) {
|
||||
return false;
|
||||
} else if(!player.canPlayerEdit(pos, side, itemstack)) {
|
||||
return false;
|
||||
} else if(world.mayPlace(Blocks.MOB_SPAWNER, pos, false, side, null)) {
|
||||
int meta = this.getMetadata(itemstack.getMetadata());
|
||||
IBlockState iblockstate1 = Blocks.MOB_SPAWNER.getStateForPlacement(world, pos, side, xOffset, yOffset, zOffset, meta, player);
|
||||
if(!world.isRemote) {
|
||||
TileEntity te = world.getTileEntity(pos);
|
||||
NBTTagCompound tag = mover.getTag();
|
||||
if (te instanceof TileEntityMobSpawner && tag.contains(TAG_SPAWNER)) {
|
||||
tag = tag.getCompound(TAG_SPAWNER);
|
||||
tag.putInt("x", pos.getX());
|
||||
tag.putInt("y", pos.getY());
|
||||
tag.putInt("z", pos.getZ());
|
||||
te.read(tag);
|
||||
VanillaPacketDispatcher.dispatchTEToNearbyPlayers(world, pos);
|
||||
}
|
||||
|
||||
if (placeBlockAt(itemstack, player, world, pos, side, xOffset, yOffset, zOffset, iblockstate1)) {
|
||||
world.playSound(null, pos, Blocks.MOB_SPAWNER.getSoundType().getPlaceSound(), SoundCategory.BLOCKS, (Blocks.MOB_SPAWNER.getSoundType().getVolume() + 1.0F) / 2.0F, Blocks.MOB_SPAWNER.getSoundType().getPitch() * 0.8F);
|
||||
player.renderBrokenItemStack(itemstack);
|
||||
itemstack.shrink(1);
|
||||
if(ctx.getPlayer() != null)
|
||||
ctx.getPlayer().renderBrokenItemStack(mover);
|
||||
mover.shrink(1);
|
||||
} else {
|
||||
for(int i = 0; i < 100; i++)
|
||||
Botania.proxy.sparkleFX(pos.getX() + Math.random(), pos.getY() + Math.random(), pos.getZ() + Math.random(), (float) Math.random(), (float) Math.random(), (float) Math.random(), 0.45F + 0.2F * (float) Math.random(), 6);
|
||||
}
|
||||
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
// Adapted from ItemBlock.placeBlockAt
|
||||
private boolean placeBlockAt(ItemStack stack, EntityPlayer player, World world, BlockPos pos, EnumFacing side, float hitX, float hitY, float hitZ, IBlockState state) {
|
||||
if (!world.setBlockState(pos, state, 3))
|
||||
return false;
|
||||
private boolean captureSpawner(ItemUseContext ctx) {
|
||||
World world = ctx.getWorld();
|
||||
BlockPos pos = ctx.getPos();
|
||||
ItemStack stack = ctx.getItem();
|
||||
EntityPlayer player = ctx.getPlayer();
|
||||
|
||||
Block block = world.getBlockState(pos).getBlock();
|
||||
if(block == Blocks.SPAWNER) {
|
||||
TileEntity te = world.getTileEntity(pos);
|
||||
NBTTagCompound tag = stack.getTag();
|
||||
if (te instanceof TileEntityMobSpawner && tag.contains(TAG_SPAWNER)) {
|
||||
tag = tag.getCompound(TAG_SPAWNER);
|
||||
tag.putInt("x", pos.getX());
|
||||
tag.putInt("y", pos.getY());
|
||||
tag.putInt("z", pos.getZ());
|
||||
te.read(tag);
|
||||
VanillaPacketDispatcher.dispatchTEToNearbyPlayers(world, pos);
|
||||
if(world.getBlockState(pos).getBlock() == Blocks.SPAWNER) {
|
||||
if(!world.isRemote) {
|
||||
TileEntity te = world.getTileEntity(pos);
|
||||
NBTTagCompound tag = new NBTTagCompound();
|
||||
tag.put(TAG_SPAWNER, te.write(new NBTTagCompound()));
|
||||
stack.setTag(tag);
|
||||
world.destroyBlock(pos, false);
|
||||
if(player != null) {
|
||||
player.getCooldownTracker().setCooldown(this, 20);
|
||||
UseItemSuccessTrigger.INSTANCE.trigger((EntityPlayerMP) player, stack, (WorldServer) world, pos.getX(), pos.getY(), pos.getZ());
|
||||
player.renderBrokenItemStack(stack);
|
||||
}
|
||||
} else {
|
||||
for(int i = 0; i < 50; i++) {
|
||||
float red = (float) Math.random();
|
||||
float green = (float) Math.random();
|
||||
float blue = (float) Math.random();
|
||||
Botania.proxy.wispFX(pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5, red, green, blue, (float) Math.random() * 0.1F + 0.05F, (float) (Math.random() - 0.5F) * 0.15F, (float) (Math.random() - 0.5F) * 0.15F, (float) (Math.random() - 0.5F) * 0.15F);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
return true;
|
||||
} else return false;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user