TechReborn/src/main/java/techreborn/blocks/BlockQuantumChest.java

153 lines
5.1 KiB
Java
Raw Normal View History

/*
* This file is part of TechReborn, licensed under the MIT License (MIT).
*
* Copyright (c) 2017 TechReborn
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
2015-04-11 12:30:16 +02:00
package techreborn.blocks;
import net.minecraft.block.BlockDynamicLiquid;
import net.minecraft.block.BlockStaticLiquid;
2015-11-23 20:37:39 +01:00
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.item.EntityItem;
2015-04-11 12:30:16 +02:00
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemBlock;
import net.minecraft.item.ItemStack;
2015-04-11 12:30:16 +02:00
import net.minecraft.tileentity.TileEntity;
2016-03-15 09:13:05 +01:00
import net.minecraft.util.EnumFacing;
2016-03-13 19:38:41 +01:00
import net.minecraft.util.EnumHand;
2016-03-13 17:08:30 +01:00
import net.minecraft.util.math.BlockPos;
2015-04-11 12:30:16 +02:00
import net.minecraft.world.World;
import net.minecraftforge.fluids.BlockFluidBase;
import reborncore.common.blocks.BlockMachineBase;
import reborncore.common.blocks.IAdvancedRotationTexture;
2015-04-11 12:30:16 +02:00
import techreborn.Core;
import techreborn.client.EGui;
2015-06-19 01:56:07 +02:00
import techreborn.client.TechRebornCreativeTab;
2015-04-11 12:30:16 +02:00
import techreborn.tiles.TileQuantumChest;
import techreborn.tiles.TileTechStorageBase;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
2015-04-11 12:30:16 +02:00
2016-10-08 21:46:16 +02:00
public class BlockQuantumChest extends BlockMachineBase implements IAdvancedRotationTexture {
2016-03-25 10:47:34 +01:00
private final String prefix = "techreborn:blocks/machine/greg_machines/";
2016-10-08 21:46:16 +02:00
public BlockQuantumChest() {
2016-03-25 10:47:34 +01:00
super();
this.setUnlocalizedName("techreborn.quantumChest");
this.setCreativeTab(TechRebornCreativeTab.instance);
this.setHardness(2.0F);
2016-03-25 10:47:34 +01:00
}
@Override
protected void dropInventory(final World world, final BlockPos pos) {
final TileEntity tileEntity = world.getTileEntity(pos);
if (tileEntity == null) {
return;
}
if (!(tileEntity instanceof TileTechStorageBase)) {
return;
}
final TileTechStorageBase inventory = (TileTechStorageBase) tileEntity;
final List<ItemStack> items = new ArrayList<>();
final List<ItemStack> droppables = inventory.getContentDrops();
for (int i = 0; i < droppables.size(); i++) {
final ItemStack itemStack = droppables.get(i);
if (itemStack == ItemStack.EMPTY) {
continue;
}
if (itemStack != ItemStack.EMPTY && itemStack.getCount() > 0) {
if (itemStack.getItem() instanceof ItemBlock) {
if (((ItemBlock) itemStack.getItem()).block instanceof BlockFluidBase
2017-06-12 15:23:32 +02:00
|| ((ItemBlock) itemStack.getItem()).block instanceof BlockStaticLiquid
|| ((ItemBlock) itemStack.getItem()).block instanceof BlockDynamicLiquid) {
continue;
}
}
}
items.add(itemStack.copy());
}
for (final ItemStack itemStack : items) {
final Random rand = new Random();
final float dX = rand.nextFloat() * 0.8F + 0.1F;
final float dY = rand.nextFloat() * 0.8F + 0.1F;
final float dZ = rand.nextFloat() * 0.8F + 0.1F;
final EntityItem entityItem = new EntityItem(world, pos.getX() + dX, pos.getY() + dY, pos.getZ() + dZ,
2017-06-12 15:23:32 +02:00
itemStack.copy());
if (itemStack.hasTagCompound()) {
entityItem.getEntityItem().setTagCompound(itemStack.getTagCompound().copy());
}
final float factor = 0.05F;
entityItem.motionX = rand.nextGaussian() * factor;
entityItem.motionY = rand.nextGaussian() * factor + 0.2F;
entityItem.motionZ = rand.nextGaussian() * factor;
world.spawnEntity(entityItem);
itemStack.setCount(0);
}
}
2016-03-25 10:47:34 +01:00
@Override
public TileEntity createNewTileEntity(final World p_149915_1_, final int p_149915_2_) {
2016-03-25 10:47:34 +01:00
return new TileQuantumChest();
}
@Override
public boolean onBlockActivated(final World worldIn, final BlockPos pos, final IBlockState state, final EntityPlayer playerIn,
2017-06-12 15:23:32 +02:00
final EnumHand hand, final EnumFacing side, final float hitX, final float hitY, final float hitZ) {
2016-03-25 10:47:34 +01:00
if (!playerIn.isSneaking())
playerIn.openGui(Core.INSTANCE, EGui.QUANTUM_CHEST.ordinal(), worldIn, pos.getX(), pos.getY(), pos.getZ());
2016-03-25 10:47:34 +01:00
return true;
}
@Override
public String getFront(final boolean isActive) {
return this.prefix + "quantum_chest";
}
@Override
public String getSide(final boolean isActive) {
return this.prefix + "qchest_side";
}
@Override
public String getTop(final boolean isActive) {
return this.prefix + "quantum_top";
}
@Override
public String getBottom(final boolean isActive) {
return this.prefix + "machine_bottom";
}
2015-04-11 12:30:16 +02:00
}