diff options
author | NotAPenguin <michiel.vandeginste@gmail.com> | 2024-09-02 23:17:17 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-09-02 23:17:17 +0200 |
commit | 1b820de08a05070909a267e17f033fcf58ac8710 (patch) | |
tree | 02831a025986a06b20f87e5bcc69d1e0c639a342 /src/main/java/kekztech/common/blocks/BlockThaumiumReinforcedJar.java | |
parent | afd3fd92b6a6ab9ab0d0dc3214e6bc8ff7a86c9b (diff) | |
download | GT5-Unofficial-1b820de08a05070909a267e17f033fcf58ac8710.tar.gz GT5-Unofficial-1b820de08a05070909a267e17f033fcf58ac8710.tar.bz2 GT5-Unofficial-1b820de08a05070909a267e17f033fcf58ac8710.zip |
The Great Renaming (#3014)
* move kekztech to a single root dir
* move detrav to a single root dir
* move gtnh-lanthanides to a single root dir
* move tectech and delete some gross reflection in gt++
* remove more reflection inside gt5u
* delete more reflection in gt++
* fix imports
* move bartworks and bwcrossmod
* fix proxies
* move galactigreg and ggfab
* move gtneioreplugin
* try to fix gt++ bee loader
* apply the rename rules to BW
* apply rename rules to bwcrossmod
* apply rename rules to detrav scanner mod
* apply rename rules to galacticgreg
* apply rename rules to ggfab
* apply rename rules to goodgenerator
* apply rename rules to gtnh-lanthanides
* apply rename rules to gt++
* apply rename rules to kekztech
* apply rename rules to kubatech
* apply rename rules to tectech
* apply rename rules to gt
apply the rename rules to gt
* fix tt import
* fix mui hopefully
* fix coremod except intergalactic
* rename assline recipe class
* fix a class name i stumbled on
* rename StructureUtility to GTStructureUtility to prevent conflict with structurelib
* temporary rename of GTTooltipDataCache to old name
* fix gt client/server proxy names
Diffstat (limited to 'src/main/java/kekztech/common/blocks/BlockThaumiumReinforcedJar.java')
-rw-r--r-- | src/main/java/kekztech/common/blocks/BlockThaumiumReinforcedJar.java | 251 |
1 files changed, 251 insertions, 0 deletions
diff --git a/src/main/java/kekztech/common/blocks/BlockThaumiumReinforcedJar.java b/src/main/java/kekztech/common/blocks/BlockThaumiumReinforcedJar.java new file mode 100644 index 0000000000..ebeb66f108 --- /dev/null +++ b/src/main/java/kekztech/common/blocks/BlockThaumiumReinforcedJar.java @@ -0,0 +1,251 @@ +package kekztech.common.blocks; + +import java.util.ArrayList; +import java.util.List; + +import net.minecraft.block.Block; +import net.minecraft.client.renderer.texture.IIconRegister; +import net.minecraft.creativetab.CreativeTabs; +import net.minecraft.entity.item.EntityItem; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.world.Explosion; +import net.minecraft.world.World; + +import cpw.mods.fml.common.registry.GameRegistry; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; +import kekztech.common.itemBlocks.ItemBlockThaumiumReinforcedJar; +import kekztech.common.tileentities.TileEntityThaumiumReinforcedJar; +import kekztech.common.tileentities.TileEntityThaumiumReinforcedVoidJar; +import thaumcraft.api.aspects.Aspect; +import thaumcraft.api.aspects.AspectList; +import thaumcraft.common.blocks.BlockJar; +import thaumcraft.common.config.ConfigBlocks; +import thaumcraft.common.config.ConfigItems; +import thaumcraft.common.items.ItemEssence; +import thaumcraft.common.tiles.TileJarFillable; + +public class BlockThaumiumReinforcedJar extends BlockJar { + + private static final BlockThaumiumReinforcedJar INSTANCE = new BlockThaumiumReinforcedJar(); + + private BlockThaumiumReinforcedJar() { + super(); + + super.setHardness(6.0F); + super.setResistance(6.0F); + } + + public static Block registerBlock() { + final String blockName = "kekztech_thaumiumreinforcedjar_block"; + INSTANCE.setBlockName(blockName); + INSTANCE.setHarvestLevel("pickaxe", 2); + GameRegistry.registerBlock(INSTANCE, ItemBlockThaumiumReinforcedJar.class, blockName); + + return INSTANCE; + } + + @Override + @SideOnly(Side.CLIENT) + public void registerBlockIcons(IIconRegister ir) { + super.iconLiquid = ir.registerIcon("thaumcraft:animatedglow"); + super.iconJarSide = ir.registerIcon("kekztech:thaumreinforced_jar_side"); + super.iconJarTop = ir.registerIcon("kekztech:thaumreinforced_jar_top"); + super.iconJarTopVoid = ir.registerIcon("kekztech:thaumreinforced_jar_top_void"); + super.iconJarSideVoid = ir.registerIcon("kekztech:thaumreinforced_jar_side_void"); + super.iconJarBottom = ir.registerIcon("kekztech:thaumreinforced_jar_bottom"); + } + + @Override + @SideOnly(Side.CLIENT) + @SuppressWarnings({ "unchecked" }) + public void getSubBlocks(Item par1, CreativeTabs par2CreativeTabs, List par3List) { + par3List.add(new ItemStack(par1, 1, 0)); // Normal jar + par3List.add(new ItemStack(par1, 1, 3)); // Void jar + } + + @Override + public TileEntity createTileEntity(World world, int meta) { + if (meta == 3) { + return new TileEntityThaumiumReinforcedVoidJar(); + } else { + return new TileEntityThaumiumReinforcedJar(); + } + } + + @Override + public void breakBlock(World world, int x, int y, int z, Block par5, int par6) { + final TileEntity te = world.getTileEntity(x, y, z); + if (te instanceof TileEntityThaumiumReinforcedJar) { + final TileEntityThaumiumReinforcedJar ite = (TileEntityThaumiumReinforcedJar) te; + breakBlockWarpy(world, x, y, z, ite.amount, 50, 1.0F); + } else if (te instanceof TileEntityThaumiumReinforcedVoidJar) { + final TileEntityThaumiumReinforcedVoidJar ite = (TileEntityThaumiumReinforcedVoidJar) te; + breakBlockWarpy(world, x, y, z, ite.amount, 50, 1.0F); + } + super.breakBlock(world, x, y, z, par5, par6); + } + + private void breakBlockWarpy(World world, int x, int y, int z, int fillAmount, int iterations, + float explosionStrength) { + if (fillAmount > 0) { + // Create a decent explosion in the center of the block (TNT has strength 4.0F) + world.createExplosion(null, x + 0.5D, y + 0.5D, z + 0.5D, explosionStrength, false); + + // Place a lot of Flux in the area + final int limit = fillAmount / 16; + int created = 0; + for (int i = 0; i < iterations; i++) { + final int xf = x + world.rand.nextInt(7) - world.rand.nextInt(7); + final int yf = x + world.rand.nextInt(7) - world.rand.nextInt(7); + final int zf = x + world.rand.nextInt(7) - world.rand.nextInt(7); + if (world.isAirBlock(xf, yf, zf)) { + if (yf > y) { + world.setBlock(xf, yf, zf, ConfigBlocks.blockFluxGas, 8, 3); + } else { + world.setBlock(xf, yf, zf, ConfigBlocks.blockFluxGoo, 8, 3); + } + + if (created++ > limit) { + break; + } + } + } + } + } + + @Override + public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int side, float f1, float f2, + float f3) { + // Call parent method to handle jar emptying, labels stuff etc + super.onBlockActivated(world, x, y, z, player, side, f1, f2, f3); + // Interact with Essentia Phials if the player holds one + final ItemStack heldItem = player.getHeldItem(); + if (heldItem != null && heldItem.getItem() == ConfigItems.itemEssence) { + final TileEntity te = world.getTileEntity(x, y, z); + if (te instanceof TileEntityThaumiumReinforcedJar) { + return dealWithPhial(world, player, x, y, z); + } else if (te instanceof TileEntityThaumiumReinforcedVoidJar) { + return dealWithPhial(world, player, x, y, z); + } + } + + return true; + } + + /** + * Handle compatibility with Essentia Phials + * + * @param world Pass through from onBlockActivated() + * @param player Pass through from onBlockActivated() + * @param x Pass through from onBlockActivated() + * @param y Pass through from onBlockActivated() + * @param z Pass through from onBlockActivated() + * @return Not sure tbh + */ + private boolean dealWithPhial(World world, EntityPlayer player, int x, int y, int z) { + final TileJarFillable kte = (TileJarFillable) world.getTileEntity(x, y, z); + final ItemStack heldItem = player.getHeldItem(); + // Check whether to fill or to drain the phial + if (heldItem.getItemDamage() == 0) { + if (kte.amount >= 8) { + if (world.isRemote) { + player.swingItem(); + return false; + } + + final Aspect jarAspect = Aspect.getAspect(kte.aspect.getTag()); + if (kte.takeFromContainer(jarAspect, 8)) { + // Take an empty phial from the player's inventory + heldItem.stackSize--; + // Fill a new phial + final ItemStack filledPhial = new ItemStack(ConfigItems.itemEssence, 1, 1); + final AspectList phialContent = new AspectList().add(jarAspect, 8); + ((ItemEssence) ConfigItems.itemEssence).setAspects(filledPhial, phialContent); + // Drop on ground if there's no inventory space + if (!player.inventory.addItemStackToInventory(filledPhial)) { + world.spawnEntityInWorld( + new EntityItem(world, (float) x + 0.5F, (float) y + 0.5F, (float) z + 0.5F, filledPhial)); + } + + world.playSoundAtEntity(player, "game.neutral.swim", 0.25F, 1.0F); + player.inventoryContainer.detectAndSendChanges(); + return true; + } + } + } else { + final AspectList phialContent = ((ItemEssence) ConfigItems.itemEssence).getAspects(heldItem); + if (phialContent != null && phialContent.size() == 1) { + final Aspect phialAspect = phialContent.getAspects()[0]; + if (kte.amount + 8 <= kte.maxAmount && kte.doesContainerAccept(phialAspect)) { + if (world.isRemote) { + player.swingItem(); + return false; + } + + if (kte.addToContainer(phialAspect, 8) == 0) { + world.markBlockForUpdate(x, y, z); + kte.markDirty(); + heldItem.stackSize--; + // Drop on ground if there's no inventory space + if (!player.inventory.addItemStackToInventory(new ItemStack(ConfigItems.itemEssence, 1, 0))) { + world.spawnEntityInWorld( + new EntityItem( + world, + (float) x + 0.5F, + (float) y + 0.5F, + (float) z + 0.5F, + new ItemStack(ConfigItems.itemEssence, 1, 0))); + } + + world.playSoundAtEntity(player, "game.neutral.swim", 0.25F, 1.0F); + player.inventoryContainer.detectAndSendChanges(); + return true; + } + } + } + } + + return true; + } + + @Override + public ArrayList<ItemStack> getDrops(World world, int x, int y, int z, int meta, int fortune) { + final ArrayList<ItemStack> drops = new ArrayList<>(); + drops.add(new ItemStack(this, 1, (meta == 3) ? 3 : 0)); + final TileEntity te = world.getTileEntity(x, y, z); + if (te instanceof TileEntityThaumiumReinforcedJar) { + final TileEntityThaumiumReinforcedJar ite = (TileEntityThaumiumReinforcedJar) te; + if (ite.aspectFilter != null) { + final ItemStack droppedLabel = new ItemStack(ConfigItems.itemResource, 1, 13); + droppedLabel.setTagCompound(new NBTTagCompound()); + final AspectList aspect = new AspectList().add(ite.aspectFilter, 0); + aspect.writeToNBT(droppedLabel.getTagCompound()); + drops.add(droppedLabel); + } + } else if (te instanceof TileEntityThaumiumReinforcedVoidJar) { + final TileEntityThaumiumReinforcedVoidJar ite = (TileEntityThaumiumReinforcedVoidJar) te; + if (ite.aspectFilter != null) { + final ItemStack droppedLabel = new ItemStack(ConfigItems.itemResource, 1, 13); + droppedLabel.setTagCompound(new NBTTagCompound()); + final AspectList aspect = new AspectList().add(ite.aspectFilter, 0); + aspect.writeToNBT(droppedLabel.getTagCompound()); + drops.add(droppedLabel); + } + } + return drops; + } + + @Override + public void onBlockHarvested(World par1World, int par2, int par3, int par4, int par5, + EntityPlayer par6EntityPlayer) {} + + @Override + public boolean canDropFromExplosion(Explosion e) { + return false; + } +} |