TechReborn/src/main/java/techreborn/itemblocks/ItemBlockDigitalChest.java

76 lines
3 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-06-07 04:11:13 +02:00
package techreborn.itemblocks;
import net.minecraft.block.Block;
2015-11-23 20:19:18 +01:00
import net.minecraft.block.state.IBlockState;
2017-06-11 22:22:07 +02:00
import net.minecraft.client.util.ITooltipFlag;
2015-06-07 04:11:13 +02:00
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemBlock;
import net.minecraft.item.ItemStack;
2015-11-23 20:19:18 +01:00
import net.minecraft.util.EnumFacing;
2016-03-15 09:13:05 +01:00
import net.minecraft.util.math.BlockPos;
2015-06-07 04:11:13 +02:00
import net.minecraft.world.World;
2015-11-23 20:19:18 +01:00
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
2015-06-07 04:11:13 +02:00
import techreborn.tiles.TileDigitalChest;
2015-07-02 20:51:24 +02:00
2016-10-08 21:46:16 +02:00
import java.util.List;
public class ItemBlockDigitalChest extends ItemBlock {
2015-06-07 04:11:13 +02:00
2016-10-08 21:46:16 +02:00
public ItemBlockDigitalChest(Block p_i45328_1_) {
2016-03-25 10:47:34 +01:00
super(p_i45328_1_);
}
2015-06-07 04:11:13 +02:00
2016-03-25 10:47:34 +01:00
@SuppressWarnings({ "rawtypes", "unchecked" })
@Override
@SideOnly(Side.CLIENT)
2017-06-11 22:22:07 +02:00
public void addInformation(ItemStack stack, World world, List list, ITooltipFlag flag) {
if (!stack.isEmpty() && stack.hasTagCompound()) {
2016-03-25 10:47:34 +01:00
if (stack.getTagCompound().getCompoundTag("tileEntity") != null)
list.add(stack.getTagCompound().getCompoundTag("tileEntity").getInteger("storedQuantity") + " items");
}
}
2015-06-07 04:11:13 +02:00
2016-03-25 10:47:34 +01:00
@Override
public boolean placeBlockAt(ItemStack stack, EntityPlayer player, World world, BlockPos pos, EnumFacing side,
2016-10-08 21:46:16 +02:00
float hitX, float hitY, float hitZ, IBlockState newState) {
if (!world.setBlockState(pos, newState)) {
2016-03-25 10:47:34 +01:00
return false;
}
2016-10-08 21:46:16 +02:00
if (world.getBlockState(pos).getBlock() == block) {
2016-03-25 10:47:34 +01:00
world.getBlockState(pos).getBlock().onBlockPlacedBy(world, pos, newState, player, stack);
// world.getBlockState(pos).getBlock().onPostBlockPlaced(world, x,
// y, z, metadata);
}
if (!stack.isEmpty() && stack.hasTagCompound()) {
2016-03-25 10:47:34 +01:00
((TileDigitalChest) world.getTileEntity(pos))
2016-10-08 21:46:16 +02:00
.readFromNBTWithoutCoords(stack.getTagCompound().getCompoundTag("tileEntity"));
2016-03-25 10:47:34 +01:00
}
return true;
}
2015-06-07 04:11:13 +02:00
}