2017-02-23 13:29:43 +01:00
|
|
|
/*
|
|
|
|
* 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-06-07 04:11:13 +02:00
|
|
|
package techreborn.blocks;
|
|
|
|
|
2016-12-18 22:06:07 +01:00
|
|
|
import net.minecraft.block.BlockDynamicLiquid;
|
|
|
|
import net.minecraft.block.BlockStaticLiquid;
|
|
|
|
import net.minecraft.entity.item.EntityItem;
|
|
|
|
import net.minecraft.item.ItemBlock;
|
|
|
|
import net.minecraft.item.ItemStack;
|
2015-06-07 04:11:13 +02:00
|
|
|
import net.minecraft.tileentity.TileEntity;
|
2016-12-18 22:06:07 +01:00
|
|
|
import net.minecraft.util.math.BlockPos;
|
2015-06-07 04:11:13 +02:00
|
|
|
import net.minecraft.world.World;
|
2016-12-18 22:06:07 +01:00
|
|
|
import net.minecraftforge.fluids.BlockFluidBase;
|
2017-06-14 01:49:52 +02:00
|
|
|
import prospector.shootingstar.ShootingStar;
|
|
|
|
import prospector.shootingstar.model.ModelCompound;
|
2017-09-06 14:46:12 +02:00
|
|
|
import reborncore.api.tile.IMachineGuiHandler;
|
2016-02-20 17:59:31 +01:00
|
|
|
import reborncore.common.blocks.BlockMachineBase;
|
2017-01-08 20:34:46 +01:00
|
|
|
import techreborn.client.EGui;
|
2016-02-20 17:59:31 +01:00
|
|
|
import techreborn.client.TechRebornCreativeTab;
|
2017-06-14 01:49:52 +02:00
|
|
|
import techreborn.lib.ModInfo;
|
2015-06-07 04:11:13 +02:00
|
|
|
import techreborn.tiles.TileDigitalChest;
|
2016-12-18 22:06:07 +01:00
|
|
|
import techreborn.tiles.TileTechStorageBase;
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.Random;
|
2015-06-07 04:11:13 +02:00
|
|
|
|
2017-06-14 01:49:52 +02:00
|
|
|
public class BlockDigitalChest extends BlockMachineBase {
|
2016-03-25 10:47:34 +01:00
|
|
|
|
2016-10-08 21:46:16 +02:00
|
|
|
public BlockDigitalChest() {
|
2016-03-25 10:47:34 +01:00
|
|
|
super();
|
2017-01-08 20:34:46 +01:00
|
|
|
this.setUnlocalizedName("techreborn.digitalChest");
|
|
|
|
this.setCreativeTab(TechRebornCreativeTab.instance);
|
2017-06-14 01:49:52 +02:00
|
|
|
ShootingStar.registerModel(new ModelCompound(ModInfo.MOD_ID, this, "machines/tier2_machines"));
|
2016-03-25 10:47:34 +01:00
|
|
|
}
|
|
|
|
|
2016-12-18 22:06:07 +01:00
|
|
|
@Override
|
2017-01-08 20:34:46 +01:00
|
|
|
protected void dropInventory(final World world, final BlockPos pos) {
|
|
|
|
final TileEntity tileEntity = world.getTileEntity(pos);
|
2016-12-18 22:06:07 +01:00
|
|
|
|
|
|
|
if (tileEntity == null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (!(tileEntity instanceof TileTechStorageBase)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-01-08 20:34:46 +01:00
|
|
|
final TileTechStorageBase inventory = (TileTechStorageBase) tileEntity;
|
2016-12-18 22:06:07 +01:00
|
|
|
|
2017-01-08 20:34:46 +01:00
|
|
|
final List<ItemStack> items = new ArrayList<>();
|
2016-12-18 22:06:07 +01:00
|
|
|
|
2017-01-08 20:34:46 +01:00
|
|
|
final List<ItemStack> droppables = inventory.getContentDrops();
|
2016-12-18 22:06:07 +01:00
|
|
|
for (int i = 0; i < droppables.size(); i++) {
|
2017-01-08 20:34:46 +01:00
|
|
|
final ItemStack itemStack = droppables.get(i);
|
2016-12-18 22:06:07 +01:00
|
|
|
|
2017-08-25 20:08:15 +02:00
|
|
|
if (itemStack.isEmpty()) {
|
2016-12-18 22:06:07 +01:00
|
|
|
continue;
|
|
|
|
}
|
2017-08-25 20:08:15 +02:00
|
|
|
if (!itemStack.isEmpty() && itemStack.getCount() > 0) {
|
2016-12-18 22:06:07 +01:00
|
|
|
if (itemStack.getItem() instanceof ItemBlock) {
|
2017-06-24 21:15:49 +02:00
|
|
|
if (((ItemBlock) itemStack.getItem()).getBlock() instanceof BlockFluidBase
|
2017-09-01 12:42:39 +02:00
|
|
|
|| ((ItemBlock) itemStack.getItem()).getBlock() instanceof BlockStaticLiquid
|
|
|
|
|| ((ItemBlock) itemStack.getItem()).getBlock() instanceof BlockDynamicLiquid) {
|
2016-12-18 22:06:07 +01:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
items.add(itemStack.copy());
|
|
|
|
}
|
|
|
|
|
2017-01-08 20:34:46 +01:00
|
|
|
for (final ItemStack itemStack : items) {
|
|
|
|
final Random rand = new Random();
|
2016-12-18 22:06:07 +01:00
|
|
|
|
2017-01-08 20:34:46 +01:00
|
|
|
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;
|
2016-12-18 22:06:07 +01:00
|
|
|
|
2017-01-08 20:34:46 +01:00
|
|
|
final EntityItem entityItem = new EntityItem(world, pos.getX() + dX, pos.getY() + dY, pos.getZ() + dZ,
|
2017-09-01 12:42:39 +02:00
|
|
|
itemStack.copy());
|
2016-12-18 22:06:07 +01:00
|
|
|
|
|
|
|
if (itemStack.hasTagCompound()) {
|
2017-06-13 23:07:49 +02:00
|
|
|
entityItem.getItem().setTagCompound(itemStack.getTagCompound().copy());
|
2016-12-18 22:06:07 +01:00
|
|
|
}
|
|
|
|
|
2017-01-08 20:34:46 +01:00
|
|
|
final float factor = 0.05F;
|
2016-12-18 22:06:07 +01:00
|
|
|
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
|
2017-01-08 20:34:46 +01:00
|
|
|
public TileEntity createNewTileEntity(final World p_149915_1_, final int p_149915_2_) {
|
2016-03-25 10:47:34 +01:00
|
|
|
return new TileDigitalChest();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2017-09-06 14:46:12 +02:00
|
|
|
public IMachineGuiHandler getGui() {
|
|
|
|
return EGui.DIGITAL_CHEST;
|
2016-03-25 10:47:34 +01:00
|
|
|
}
|
2015-06-07 04:11:13 +02:00
|
|
|
}
|