mirror of
https://github.com/Ellpeck/ActuallyAdditions.git
synced 2024-12-22 19:39:24 +01:00
More porting of blocks
This commit is contained in:
parent
06a2957f27
commit
4d5cc7aa58
7 changed files with 480 additions and 510 deletions
|
@ -1,4 +1,7 @@
|
|||
package de.ellpeck.actuallyadditions.client;
|
||||
|
||||
import net.minecraftforge.fml.client.gui.GuiUtils;
|
||||
|
||||
public class ClientSetup {
|
||||
GuiUtils
|
||||
}
|
||||
|
|
|
@ -1,38 +1,30 @@
|
|||
package de.ellpeck.actuallyadditions.common.blocks;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
import de.ellpeck.actuallyadditions.common.ActuallyAdditions;
|
||||
import de.ellpeck.actuallyadditions.common.blocks.metalists.TheColoredLampColors;
|
||||
import de.ellpeck.actuallyadditions.common.util.StackUtil;
|
||||
import de.ellpeck.actuallyadditions.common.util.StringUtil;
|
||||
import de.ellpeck.actuallyadditions.common.util.Util;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.block.material.Material;
|
||||
import net.minecraft.block.properties.PropertyEnum;
|
||||
import net.minecraft.block.state.BlockStateContainer;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.creativetab.CreativeTabs;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.item.BlockItem;
|
||||
import net.minecraft.item.EnumRarity;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.EnumHand;
|
||||
import net.minecraft.util.ActionResultType;
|
||||
import net.minecraft.util.Direction;
|
||||
import net.minecraft.util.Hand;
|
||||
import net.minecraft.util.NonNullList;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.IBlockAccess;
|
||||
import net.minecraft.util.math.BlockRayTraceResult;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.ToolType;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
import net.minecraftforge.oredict.OreDictionary;
|
||||
|
||||
public class BlockColoredLamp extends Block {
|
||||
|
||||
public static final TheColoredLampColors[] ALL_LAMP_TYPES = TheColoredLampColors.values();
|
||||
public static final PropertyEnum<TheColoredLampColors> TYPE = PropertyEnum.create("type", TheColoredLampColors.class);
|
||||
// todo: replace with flattered versions
|
||||
// public static final TheColoredLampColors[] ALL_LAMP_TYPES = TheColoredLampColors.values();
|
||||
// public static final PropertyEnum<TheColoredLampColors> TYPE = PropertyEnum.create("type", TheColoredLampColors.class);
|
||||
public final boolean isOn;
|
||||
|
||||
public BlockColoredLamp(boolean isOn) {
|
||||
|
@ -43,113 +35,96 @@ public class BlockColoredLamp extends Block {
|
|||
this.isOn = isOn;
|
||||
}
|
||||
|
||||
// @Override
|
||||
// public Item getItemDropped(Block block) {
|
||||
// return Item.getItemFromBlock(InitBlocks.blockColoredLamp);
|
||||
// }
|
||||
|
||||
// @Override
|
||||
// public int damageDropped(BlockState state) {
|
||||
// return this.getMetaFromState(state);
|
||||
// }
|
||||
|
||||
|
||||
// todo: re-implement
|
||||
@Override
|
||||
public Item getItemDropped(IBlockState state, Random rand, int par3) {
|
||||
return Item.getItemFromBlock(InitBlocks.blockColoredLamp);
|
||||
public ActionResultType onBlockActivated(BlockState state, World worldIn, BlockPos pos, PlayerEntity player, Hand handIn, BlockRayTraceResult hit) {
|
||||
// ItemStack stack = player.getHeldItem(hand);
|
||||
// //Turning On
|
||||
// if (hand == EnumHand.MAIN_HAND && stack.isEmpty()) {
|
||||
// world.setBlockState(pos, (this.isOn ? InitBlocks.blockColoredLamp : InitBlocks.blockColoredLampOn).getDefaultState().withProperty(TYPE, state.getValue(TYPE)), 2);
|
||||
// world.notifyLightSet(pos);
|
||||
// return true;
|
||||
// }
|
||||
//
|
||||
// if (StackUtil.isValid(stack)) {
|
||||
// //Changing Colors
|
||||
// int[] oreIDs = OreDictionary.getOreIDs(stack);
|
||||
// if (oreIDs.length > 0) {
|
||||
// for (int oreID : oreIDs) {
|
||||
// String name = OreDictionary.getOreName(oreID);
|
||||
// TheColoredLampColors color = TheColoredLampColors.getColorFromDyeName(name);
|
||||
// if (color != null) {
|
||||
// if (this.getMetaFromState(state) != color.ordinal()) {
|
||||
// if (!world.isRemote) {
|
||||
// world.setBlockState(pos, this.getStateFromMeta(color.ordinal()), 2);
|
||||
// if (!player.capabilities.isCreativeMode) {
|
||||
// player.inventory.decrStackSize(player.inventory.currentItem, 1);
|
||||
// }
|
||||
// }
|
||||
// return true;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
return super.onBlockActivated(state, worldIn, pos, player, handIn, hit);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int damageDropped(IBlockState state) {
|
||||
return this.getMetaFromState(state);
|
||||
}
|
||||
// @Override
|
||||
// @SideOnly(Side.CLIENT)
|
||||
// public void getSubBlocks(CreativeTabs tab, NonNullList<ItemStack> list) {
|
||||
// for (int j = 0; j < ALL_LAMP_TYPES.length; j++) {
|
||||
// list.add(new ItemStack(this, 1, j));
|
||||
// }
|
||||
// }
|
||||
|
||||
|
||||
@Override
|
||||
public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, EnumFacing side, float hitX, float hitY, float hitZ) {
|
||||
ItemStack stack = player.getHeldItem(hand);
|
||||
//Turning On
|
||||
if (hand == EnumHand.MAIN_HAND && stack.isEmpty()) {
|
||||
world.setBlockState(pos, (this.isOn ? InitBlocks.blockColoredLamp : InitBlocks.blockColoredLampOn).getDefaultState().withProperty(TYPE, state.getValue(TYPE)), 2);
|
||||
world.notifyLightSet(pos);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (StackUtil.isValid(stack)) {
|
||||
//Changing Colors
|
||||
int[] oreIDs = OreDictionary.getOreIDs(stack);
|
||||
if (oreIDs.length > 0) {
|
||||
for (int oreID : oreIDs) {
|
||||
String name = OreDictionary.getOreName(oreID);
|
||||
TheColoredLampColors color = TheColoredLampColors.getColorFromDyeName(name);
|
||||
if (color != null) {
|
||||
if (this.getMetaFromState(state) != color.ordinal()) {
|
||||
if (!world.isRemote) {
|
||||
world.setBlockState(pos, this.getStateFromMeta(color.ordinal()), 2);
|
||||
if (!player.capabilities.isCreativeMode) {
|
||||
player.inventory.decrStackSize(player.inventory.currentItem, 1);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public void getSubBlocks(CreativeTabs tab, NonNullList<ItemStack> list) {
|
||||
for (int j = 0; j < ALL_LAMP_TYPES.length; j++) {
|
||||
list.add(new ItemStack(this, 1, j));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getLightValue(IBlockState state, IBlockAccess world, BlockPos pos) {
|
||||
public int getLightValue(BlockState state) {
|
||||
return this.isOn ? 15 : 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected BlockItemBase getItemBlock() {
|
||||
return new TheItemBlock(this);
|
||||
}
|
||||
// @Override
|
||||
// public void registerRendering() {
|
||||
// for (int i = 0; i < ALL_LAMP_TYPES.length; i++) {
|
||||
// ActuallyAdditions.PROXY.addRenderRegister(new ItemStack(this, 1, i), this.getRegistryName(), TYPE.getName() + "=" + ALL_LAMP_TYPES[i].regName);
|
||||
// }
|
||||
// }
|
||||
|
||||
@Override
|
||||
public void registerRendering() {
|
||||
for (int i = 0; i < ALL_LAMP_TYPES.length; i++) {
|
||||
ActuallyAdditions.PROXY.addRenderRegister(new ItemStack(this, 1, i), this.getRegistryName(), TYPE.getName() + "=" + ALL_LAMP_TYPES[i].regName);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public EnumRarity getRarity(ItemStack stack) {
|
||||
return EnumRarity.RARE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IBlockState getStateFromMeta(int meta) {
|
||||
return this.getDefaultState().withProperty(TYPE, TheColoredLampColors.values()[meta]);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMetaFromState(IBlockState state) {
|
||||
return state.getValue(TYPE).ordinal();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected BlockStateContainer createBlockState() {
|
||||
return new BlockStateContainer(this, TYPE);
|
||||
}
|
||||
|
||||
public static class TheItemBlock extends BlockItem {
|
||||
|
||||
public TheItemBlock(Block block) {
|
||||
super(block);
|
||||
this.setHasSubtypes(true);
|
||||
this.setMaxDamage(0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getItemStackDisplayName(ItemStack stack) {
|
||||
if (stack.getItemDamage() >= ALL_LAMP_TYPES.length) { return StringUtil.BUGGED_ITEM_NAME; }
|
||||
if (Util.isClient()) return super.getItemStackDisplayName(stack) + (((BlockColoredLamp) this.block).isOn ? " (" + StringUtil.localize("tooltip." + ActuallyAdditions.MODID + ".onSuffix.desc") + ")" : "");
|
||||
else return super.getItemStackDisplayName(stack);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTranslationKey(ItemStack stack) {
|
||||
return InitBlocks.blockColoredLamp.getTranslationKey() + "_" + ALL_LAMP_TYPES[stack.getItemDamage()].regName;
|
||||
}
|
||||
}
|
||||
// @Override
|
||||
// protected BlockStateContainer createBlockState() {
|
||||
// return new BlockStateContainer(this, TYPE);
|
||||
// }
|
||||
//
|
||||
// public static class TheItemBlock extends BlockItem {
|
||||
//
|
||||
// public TheItemBlock(Block block) {
|
||||
// super(block);
|
||||
// this.setHasSubtypes(true);
|
||||
// this.setMaxDamage(0);
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public String getItemStackDisplayName(ItemStack stack) {
|
||||
// if (stack.getItemDamage() >= ALL_LAMP_TYPES.length) { return StringUtil.BUGGED_ITEM_NAME; }
|
||||
// if (Util.isClient()) return super.getItemStackDisplayName(stack) + (((BlockColoredLamp) this.block).isOn ? " (" + StringUtil.localize("tooltip." + ActuallyAdditions.MODID + ".onSuffix.desc") + ")" : "");
|
||||
// else return super.getItemStackDisplayName(stack);
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public String getTranslationKey(ItemStack stack) {
|
||||
// return InitBlocks.blockColoredLamp.getTranslationKey() + "_" + ALL_LAMP_TYPES[stack.getItemDamage()].regName;
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
|
|
@ -1,213 +1,214 @@
|
|||
package de.ellpeck.actuallyadditions.common.blocks;
|
||||
|
||||
import de.ellpeck.actuallyadditions.api.recipe.CompostRecipe;
|
||||
import de.ellpeck.actuallyadditions.common.blocks.base.BlockContainerBase;
|
||||
import de.ellpeck.actuallyadditions.common.tile.TileEntityCompost;
|
||||
import de.ellpeck.actuallyadditions.common.util.AssetUtil;
|
||||
import de.ellpeck.actuallyadditions.common.util.ItemUtil;
|
||||
import de.ellpeck.actuallyadditions.common.util.StackUtil;
|
||||
import de.ellpeck.actuallyadditions.common.util.StringUtil;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.SoundType;
|
||||
import net.minecraft.block.material.Material;
|
||||
import net.minecraft.block.state.BlockStateContainer;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.ScaledResolution;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.EnumRarity;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.state.IProperty;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.BlockRenderLayer;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.EnumHand;
|
||||
import net.minecraft.util.math.AxisAlignedBB;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.RayTraceResult;
|
||||
import net.minecraft.util.text.TextFormatting;
|
||||
import net.minecraft.world.IBlockAccess;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.ToolType;
|
||||
import net.minecraftforge.common.property.ExtendedBlockState;
|
||||
import net.minecraftforge.common.property.IExtendedBlockState;
|
||||
import net.minecraftforge.common.property.IUnlistedProperty;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
import org.apache.commons.lang3.tuple.Pair;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class BlockCompost extends BlockContainerBase implements IHudDisplay {
|
||||
|
||||
protected static final AxisAlignedBB AABB_LEGS = new AxisAlignedBB(0.0D, 0.0D, 0.0D, 1.0D, 0.3125D, 1.0D);
|
||||
protected static final AxisAlignedBB AABB_WALL_NORTH = new AxisAlignedBB(0.0D, 0.0D, 0.0D, 1.0D, 1.0D, 0.125D);
|
||||
protected static final AxisAlignedBB AABB_WALL_SOUTH = new AxisAlignedBB(0.0D, 0.0D, 0.875D, 1.0D, 1.0D, 1.0D);
|
||||
protected static final AxisAlignedBB AABB_WALL_EAST = new AxisAlignedBB(0.875D, 0.0D, 0.0D, 1.0D, 1.0D, 1.0D);
|
||||
protected static final AxisAlignedBB AABB_WALL_WEST = new AxisAlignedBB(0.0D, 0.0D, 0.0D, 0.125D, 1.0D, 1.0D);
|
||||
private static final AxisAlignedBB AABB = new AxisAlignedBB(0.0625, 0, 0.0625, 1 - 0.0625, 11 * 0.0625, 1 - 0.0625);
|
||||
|
||||
public BlockCompost() {
|
||||
super(Block.Properties.create(Material.WOOD)
|
||||
.hardnessAndResistance(0.5f, 5.0f)
|
||||
.harvestTool(ToolType.AXE)
|
||||
.sound(SoundType.WOOD));
|
||||
}
|
||||
|
||||
@Override
|
||||
public AxisAlignedBB getBoundingBox(IBlockState state, IBlockAccess source, BlockPos pos) {
|
||||
return AABB;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public void addCollisionBoxToList(IBlockState state, World worldIn, BlockPos pos, AxisAlignedBB entityBox, List<AxisAlignedBB> collidingBoxes, Entity entityIn, boolean someBool) {
|
||||
addCollisionBoxToList(pos, entityBox, collidingBoxes, AABB_LEGS);
|
||||
addCollisionBoxToList(pos, entityBox, collidingBoxes, AABB_WALL_WEST);
|
||||
addCollisionBoxToList(pos, entityBox, collidingBoxes, AABB_WALL_NORTH);
|
||||
addCollisionBoxToList(pos, entityBox, collidingBoxes, AABB_WALL_EAST);
|
||||
addCollisionBoxToList(pos, entityBox, collidingBoxes, AABB_WALL_SOUTH);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isOpaqueCube(IBlockState state) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isFullCube(IBlockState state) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, EnumFacing f6, float f7, float f8, float f9) {
|
||||
ItemStack stackPlayer = player.getHeldItem(hand);
|
||||
if (!world.isRemote) {
|
||||
TileEntity tile = world.getTileEntity(pos);
|
||||
if (tile instanceof TileEntityCompost) {
|
||||
TileEntityCompost compost = (TileEntityCompost) tile;
|
||||
ItemStack slot = compost.inv.getStackInSlot(0);
|
||||
CompostRecipe recipeIn = TileEntityCompost.getRecipeForInput(slot);
|
||||
if (!StackUtil.isValid(slot) || recipeIn != null) {
|
||||
if (StackUtil.isValid(stackPlayer)) {
|
||||
CompostRecipe recipeHand = TileEntityCompost.getRecipeForInput(stackPlayer);
|
||||
if (recipeHand != null && (recipeIn == null || recipeIn == recipeHand)) {
|
||||
int maxAdd = stackPlayer.getCount();
|
||||
|
||||
if (!StackUtil.isValid(slot)) {
|
||||
ItemStack stackToAdd = stackPlayer.copy();
|
||||
stackToAdd.setCount(maxAdd);
|
||||
compost.inv.setStackInSlot(0, stackToAdd);
|
||||
player.inventory.decrStackSize(player.inventory.currentItem, maxAdd);
|
||||
return true;
|
||||
} else {
|
||||
ItemStack stackIn = slot.copy();
|
||||
if (stackIn.getCount() < slot.getMaxStackSize()) {
|
||||
int sizeAdded = Math.min(maxAdd, slot.getMaxStackSize() - stackIn.getCount());
|
||||
stackIn.grow(sizeAdded);
|
||||
compost.inv.setStackInSlot(0, stackIn);
|
||||
player.inventory.decrStackSize(player.inventory.currentItem, sizeAdded);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (!StackUtil.isValid(stackPlayer)) {
|
||||
player.setHeldItem(hand, slot.copy());
|
||||
compost.inv.setStackInSlot(0, StackUtil.getEmpty());
|
||||
return true;
|
||||
} else if (ItemUtil.canBeStacked(stackPlayer, slot)) {
|
||||
int addedStackSize = Math.min(slot.getCount(), stackPlayer.getMaxStackSize() - stackPlayer.getCount());
|
||||
ItemStack stackToAdd = stackPlayer.copy();
|
||||
stackToAdd.grow(addedStackSize);
|
||||
player.setHeldItem(hand, stackToAdd);
|
||||
compost.inv.getStackInSlot(0).shrink(addedStackSize);
|
||||
return true;
|
||||
|
||||
}
|
||||
}
|
||||
tile.markDirty();
|
||||
world.notifyBlockUpdate(pos, this.getDefaultState(), this.getDefaultState(), 3);
|
||||
}
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TileEntity createNewTileEntity(World world, int meta) {
|
||||
return new TileEntityCompost();
|
||||
}
|
||||
|
||||
@Override
|
||||
public EnumRarity getRarity(ItemStack stack) {
|
||||
return EnumRarity.UNCOMMON;
|
||||
}
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public void displayHud(Minecraft minecraft, EntityPlayer player, ItemStack stack, RayTraceResult posHit, ScaledResolution resolution) {
|
||||
TileEntity tile = minecraft.world.getTileEntity(posHit.getBlockPos());
|
||||
if (tile instanceof TileEntityCompost) {
|
||||
ItemStack slot = ((TileEntityCompost) tile).inv.getStackInSlot(0);
|
||||
String strg;
|
||||
if (!StackUtil.isValid(slot)) {
|
||||
strg = "Empty";
|
||||
} else {
|
||||
strg = slot.getDisplayName();
|
||||
|
||||
AssetUtil.renderStackToGui(slot, resolution.getScaledWidth() / 2 + 15, resolution.getScaledHeight() / 2 - 29, 1F);
|
||||
}
|
||||
minecraft.fontRenderer.drawStringWithShadow(TextFormatting.YELLOW + "" + TextFormatting.ITALIC + strg, resolution.getScaledWidth() / 2 + 35, resolution.getScaledHeight() / 2 - 25, StringUtil.DECIMAL_COLOR_WHITE);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected BlockStateContainer createBlockState() {
|
||||
return new ExtendedBlockState(this, new IProperty[0], new IUnlistedProperty[] { COMPOST_PROP });
|
||||
}
|
||||
|
||||
@Override
|
||||
public IBlockState getExtendedState(IBlockState state, IBlockAccess world, BlockPos pos) {
|
||||
TileEntity te = world.getTileEntity(pos);
|
||||
if (te instanceof TileEntityCompost && state instanceof IExtendedBlockState) {
|
||||
TileEntityCompost compost = (TileEntityCompost) te;
|
||||
return ((IExtendedBlockState) state).withProperty(COMPOST_PROP, Pair.of(compost.getCurrentDisplay(), compost.getHeight()));
|
||||
}
|
||||
return state;
|
||||
}
|
||||
|
||||
public BlockRenderLayer getBlockLayer() {
|
||||
return BlockRenderLayer.CUTOUT;
|
||||
}
|
||||
|
||||
public static CompostProperty COMPOST_PROP = new CompostProperty();
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
private static class CompostProperty implements IProperty<Pair> {
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "compost";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isValid(Pair value) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<Pair> getType() {
|
||||
return Pair.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String valueToString(Pair value) {
|
||||
return "";
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
// todo: remove
|
||||
//package de.ellpeck.actuallyadditions.common.blocks;
|
||||
//
|
||||
//import de.ellpeck.actuallyadditions.api.recipe.CompostRecipe;
|
||||
//import de.ellpeck.actuallyadditions.common.blocks.base.BlockContainerBase;
|
||||
//import de.ellpeck.actuallyadditions.common.tile.TileEntityCompost;
|
||||
//import de.ellpeck.actuallyadditions.common.util.AssetUtil;
|
||||
//import de.ellpeck.actuallyadditions.common.util.ItemUtil;
|
||||
//import de.ellpeck.actuallyadditions.common.util.StackUtil;
|
||||
//import de.ellpeck.actuallyadditions.common.util.StringUtil;
|
||||
//import net.minecraft.block.Block;
|
||||
//import net.minecraft.block.SoundType;
|
||||
//import net.minecraft.block.material.Material;
|
||||
//import net.minecraft.block.state.BlockStateContainer;
|
||||
//import net.minecraft.block.state.IBlockState;
|
||||
//import net.minecraft.client.Minecraft;
|
||||
//import net.minecraft.client.gui.ScaledResolution;
|
||||
//import net.minecraft.entity.Entity;
|
||||
//import net.minecraft.entity.player.EntityPlayer;
|
||||
//import net.minecraft.item.EnumRarity;
|
||||
//import net.minecraft.item.ItemStack;
|
||||
//import net.minecraft.state.IProperty;
|
||||
//import net.minecraft.tileentity.TileEntity;
|
||||
//import net.minecraft.util.BlockRenderLayer;
|
||||
//import net.minecraft.util.EnumFacing;
|
||||
//import net.minecraft.util.EnumHand;
|
||||
//import net.minecraft.util.math.AxisAlignedBB;
|
||||
//import net.minecraft.util.math.BlockPos;
|
||||
//import net.minecraft.util.math.RayTraceResult;
|
||||
//import net.minecraft.util.text.TextFormatting;
|
||||
//import net.minecraft.world.IBlockAccess;
|
||||
//import net.minecraft.world.World;
|
||||
//import net.minecraftforge.common.ToolType;
|
||||
//import net.minecraftforge.common.property.ExtendedBlockState;
|
||||
//import net.minecraftforge.common.property.IExtendedBlockState;
|
||||
//import net.minecraftforge.common.property.IUnlistedProperty;
|
||||
//import net.minecraftforge.fml.relauncher.Side;
|
||||
//import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
//import org.apache.commons.lang3.tuple.Pair;
|
||||
//
|
||||
//import java.util.List;
|
||||
//
|
||||
//public class BlockCompost extends BlockContainerBase implements IHudDisplay {
|
||||
//
|
||||
// protected static final AxisAlignedBB AABB_LEGS = new AxisAlignedBB(0.0D, 0.0D, 0.0D, 1.0D, 0.3125D, 1.0D);
|
||||
// protected static final AxisAlignedBB AABB_WALL_NORTH = new AxisAlignedBB(0.0D, 0.0D, 0.0D, 1.0D, 1.0D, 0.125D);
|
||||
// protected static final AxisAlignedBB AABB_WALL_SOUTH = new AxisAlignedBB(0.0D, 0.0D, 0.875D, 1.0D, 1.0D, 1.0D);
|
||||
// protected static final AxisAlignedBB AABB_WALL_EAST = new AxisAlignedBB(0.875D, 0.0D, 0.0D, 1.0D, 1.0D, 1.0D);
|
||||
// protected static final AxisAlignedBB AABB_WALL_WEST = new AxisAlignedBB(0.0D, 0.0D, 0.0D, 0.125D, 1.0D, 1.0D);
|
||||
// private static final AxisAlignedBB AABB = new AxisAlignedBB(0.0625, 0, 0.0625, 1 - 0.0625, 11 * 0.0625, 1 - 0.0625);
|
||||
//
|
||||
// public BlockCompost() {
|
||||
// super(Block.Properties.create(Material.WOOD)
|
||||
// .hardnessAndResistance(0.5f, 5.0f)
|
||||
// .harvestTool(ToolType.AXE)
|
||||
// .sound(SoundType.WOOD));
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public AxisAlignedBB getBoundingBox(IBlockState state, IBlockAccess source, BlockPos pos) {
|
||||
// return AABB;
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// @Deprecated
|
||||
// public void addCollisionBoxToList(IBlockState state, World worldIn, BlockPos pos, AxisAlignedBB entityBox, List<AxisAlignedBB> collidingBoxes, Entity entityIn, boolean someBool) {
|
||||
// addCollisionBoxToList(pos, entityBox, collidingBoxes, AABB_LEGS);
|
||||
// addCollisionBoxToList(pos, entityBox, collidingBoxes, AABB_WALL_WEST);
|
||||
// addCollisionBoxToList(pos, entityBox, collidingBoxes, AABB_WALL_NORTH);
|
||||
// addCollisionBoxToList(pos, entityBox, collidingBoxes, AABB_WALL_EAST);
|
||||
// addCollisionBoxToList(pos, entityBox, collidingBoxes, AABB_WALL_SOUTH);
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public boolean isOpaqueCube(IBlockState state) {
|
||||
// return false;
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public boolean isFullCube(IBlockState state) {
|
||||
// return false;
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, EnumFacing f6, float f7, float f8, float f9) {
|
||||
// ItemStack stackPlayer = player.getHeldItem(hand);
|
||||
// if (!world.isRemote) {
|
||||
// TileEntity tile = world.getTileEntity(pos);
|
||||
// if (tile instanceof TileEntityCompost) {
|
||||
// TileEntityCompost compost = (TileEntityCompost) tile;
|
||||
// ItemStack slot = compost.inv.getStackInSlot(0);
|
||||
// CompostRecipe recipeIn = TileEntityCompost.getRecipeForInput(slot);
|
||||
// if (!StackUtil.isValid(slot) || recipeIn != null) {
|
||||
// if (StackUtil.isValid(stackPlayer)) {
|
||||
// CompostRecipe recipeHand = TileEntityCompost.getRecipeForInput(stackPlayer);
|
||||
// if (recipeHand != null && (recipeIn == null || recipeIn == recipeHand)) {
|
||||
// int maxAdd = stackPlayer.getCount();
|
||||
//
|
||||
// if (!StackUtil.isValid(slot)) {
|
||||
// ItemStack stackToAdd = stackPlayer.copy();
|
||||
// stackToAdd.setCount(maxAdd);
|
||||
// compost.inv.setStackInSlot(0, stackToAdd);
|
||||
// player.inventory.decrStackSize(player.inventory.currentItem, maxAdd);
|
||||
// return true;
|
||||
// } else {
|
||||
// ItemStack stackIn = slot.copy();
|
||||
// if (stackIn.getCount() < slot.getMaxStackSize()) {
|
||||
// int sizeAdded = Math.min(maxAdd, slot.getMaxStackSize() - stackIn.getCount());
|
||||
// stackIn.grow(sizeAdded);
|
||||
// compost.inv.setStackInSlot(0, stackIn);
|
||||
// player.inventory.decrStackSize(player.inventory.currentItem, sizeAdded);
|
||||
// return true;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// } else {
|
||||
// if (!StackUtil.isValid(stackPlayer)) {
|
||||
// player.setHeldItem(hand, slot.copy());
|
||||
// compost.inv.setStackInSlot(0, StackUtil.getEmpty());
|
||||
// return true;
|
||||
// } else if (ItemUtil.canBeStacked(stackPlayer, slot)) {
|
||||
// int addedStackSize = Math.min(slot.getCount(), stackPlayer.getMaxStackSize() - stackPlayer.getCount());
|
||||
// ItemStack stackToAdd = stackPlayer.copy();
|
||||
// stackToAdd.grow(addedStackSize);
|
||||
// player.setHeldItem(hand, stackToAdd);
|
||||
// compost.inv.getStackInSlot(0).shrink(addedStackSize);
|
||||
// return true;
|
||||
//
|
||||
// }
|
||||
// }
|
||||
// tile.markDirty();
|
||||
// world.notifyBlockUpdate(pos, this.getDefaultState(), this.getDefaultState(), 3);
|
||||
// }
|
||||
// } else {
|
||||
// return true;
|
||||
// }
|
||||
// return false;
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public TileEntity createNewTileEntity(World world, int meta) {
|
||||
// return new TileEntityCompost();
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public EnumRarity getRarity(ItemStack stack) {
|
||||
// return EnumRarity.UNCOMMON;
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// @SideOnly(Side.CLIENT)
|
||||
// public void displayHud(Minecraft minecraft, EntityPlayer player, ItemStack stack, RayTraceResult posHit, ScaledResolution resolution) {
|
||||
// TileEntity tile = minecraft.world.getTileEntity(posHit.getBlockPos());
|
||||
// if (tile instanceof TileEntityCompost) {
|
||||
// ItemStack slot = ((TileEntityCompost) tile).inv.getStackInSlot(0);
|
||||
// String strg;
|
||||
// if (!StackUtil.isValid(slot)) {
|
||||
// strg = "Empty";
|
||||
// } else {
|
||||
// strg = slot.getDisplayName();
|
||||
//
|
||||
// AssetUtil.renderStackToGui(slot, resolution.getScaledWidth() / 2 + 15, resolution.getScaledHeight() / 2 - 29, 1F);
|
||||
// }
|
||||
// minecraft.fontRenderer.drawStringWithShadow(TextFormatting.YELLOW + "" + TextFormatting.ITALIC + strg, resolution.getScaledWidth() / 2 + 35, resolution.getScaledHeight() / 2 - 25, StringUtil.DECIMAL_COLOR_WHITE);
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// protected BlockStateContainer createBlockState() {
|
||||
// return new ExtendedBlockState(this, new IProperty[0], new IUnlistedProperty[] { COMPOST_PROP });
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public IBlockState getExtendedState(IBlockState state, IBlockAccess world, BlockPos pos) {
|
||||
// TileEntity te = world.getTileEntity(pos);
|
||||
// if (te instanceof TileEntityCompost && state instanceof IExtendedBlockState) {
|
||||
// TileEntityCompost compost = (TileEntityCompost) te;
|
||||
// return ((IExtendedBlockState) state).withProperty(COMPOST_PROP, Pair.of(compost.getCurrentDisplay(), compost.getHeight()));
|
||||
// }
|
||||
// return state;
|
||||
// }
|
||||
//
|
||||
// public BlockRenderLayer getBlockLayer() {
|
||||
// return BlockRenderLayer.CUTOUT;
|
||||
// }
|
||||
//
|
||||
// public static CompostProperty COMPOST_PROP = new CompostProperty();
|
||||
//
|
||||
// @SuppressWarnings("rawtypes")
|
||||
// private static class CompostProperty implements IProperty<Pair> {
|
||||
//
|
||||
// @Override
|
||||
// public String getName() {
|
||||
// return "compost";
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public boolean isValid(Pair value) {
|
||||
// return true;
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public Class<Pair> getType() {
|
||||
// return Pair.class;
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public String valueToString(Pair value) {
|
||||
// return "";
|
||||
// }
|
||||
//
|
||||
// }
|
||||
//}
|
||||
|
|
|
@ -5,6 +5,7 @@ import de.ellpeck.actuallyadditions.common.blocks.base.BlockContainerBase;
|
|||
import de.ellpeck.actuallyadditions.common.inventory.GuiHandler;
|
||||
import de.ellpeck.actuallyadditions.common.tile.TileEntitySmileyCloud;
|
||||
import net.minecraft.block.BlockHorizontal;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.block.SoundType;
|
||||
import net.minecraft.block.material.Material;
|
||||
import net.minecraft.block.state.BlockStateContainer;
|
||||
|
@ -16,6 +17,7 @@ import net.minecraft.item.ItemStack;
|
|||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.*;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.IBlockReader;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.ToolType;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
|
@ -25,7 +27,7 @@ import java.util.Random;
|
|||
|
||||
public class BlockSmileyCloud extends BlockContainerBase {
|
||||
|
||||
public BlockSmileyCloud(S) {
|
||||
public BlockSmileyCloud() {
|
||||
super(Properties.create(Material.WOOL)
|
||||
.hardnessAndResistance(0.5f, 5.0f)
|
||||
.harvestTool(ToolType.PICKAXE)
|
||||
|
@ -33,6 +35,11 @@ public class BlockSmileyCloud extends BlockContainerBase {
|
|||
.tickRandomly());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isNormalCube(BlockState state, IBlockReader worldIn, BlockPos pos) {
|
||||
return super.isNormalCube(state, worldIn, pos);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isFullCube(IBlockState state) {
|
||||
return false;
|
||||
|
|
|
@ -1,127 +1,127 @@
|
|||
package de.ellpeck.actuallyadditions.common.blocks;
|
||||
|
||||
import de.ellpeck.actuallyadditions.api.ActuallyAdditionsAPI;
|
||||
import de.ellpeck.actuallyadditions.api.recipe.TreasureChestLoot;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockHorizontal;
|
||||
import net.minecraft.block.SoundType;
|
||||
import net.minecraft.block.material.Material;
|
||||
import net.minecraft.block.state.BlockStateContainer;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraft.entity.item.EntityItem;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.init.Items;
|
||||
import net.minecraft.init.SoundEvents;
|
||||
import net.minecraft.item.EnumRarity;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.*;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.MathHelper;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.ToolType;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
public class BlockTreasureChest extends Block {
|
||||
|
||||
public BlockTreasureChest() {
|
||||
super(Block.Properties.create(Material.WOOD)
|
||||
.hardnessAndResistance(300.0f, 50.0f)
|
||||
.harvestTool(ToolType.AXE)
|
||||
.sound(SoundType.WOOD)
|
||||
.tickRandomly());
|
||||
}
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public void randomDisplayTick(IBlockState state, World world, BlockPos pos, Random rand) {
|
||||
for (int i = 0; i < 2; i++) {
|
||||
for (float f = 0; f <= 3; f += 0.5) {
|
||||
float particleX = rand.nextFloat();
|
||||
float particleZ = rand.nextFloat();
|
||||
world.spawnParticle(EnumParticleTypes.WATER_BUBBLE, (double) pos.getX() + particleX, (double) pos.getY() + f + 1, (double) pos.getZ() + particleZ, 0.0D, 0.2D, 0.0D);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Item getItemDropped(IBlockState state, Random rand, int par3) {
|
||||
return Items.AIR;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, EnumFacing par6, float par7, float par8, float par9) {
|
||||
if (!world.isRemote) {
|
||||
world.playSound(null, pos, SoundEvents.BLOCK_CHEST_OPEN, SoundCategory.BLOCKS, 0.2F, world.rand.nextFloat() * 0.1F + 0.9F);
|
||||
this.dropItems(world, pos);
|
||||
world.setBlockToAir(pos);
|
||||
|
||||
//TheAchievements.OPEN_TREASURE_CHEST.get(player);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBlockPlacedBy(World world, BlockPos pos, IBlockState state, EntityLivingBase player, ItemStack stack) {
|
||||
world.setBlockState(pos, state.withProperty(BlockHorizontal.FACING, player.getHorizontalFacing().getOpposite()), 2);
|
||||
|
||||
super.onBlockPlacedBy(world, pos, state, player, stack);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canSilkHarvest(World world, BlockPos pos, IBlockState state, EntityPlayer player) {
|
||||
return false;
|
||||
}
|
||||
|
||||
private void dropItems(World world, BlockPos pos) {
|
||||
for (int i = 0; i < MathHelper.getInt(world.rand, 3, 6); i++) {
|
||||
TreasureChestLoot theReturn = WeightedRandom.getRandomItem(world.rand, ActuallyAdditionsAPI.TREASURE_CHEST_LOOT);
|
||||
ItemStack itemStack = theReturn.returnItem.copy();
|
||||
itemStack.setCount(MathHelper.getInt(world.rand, theReturn.minAmount, theReturn.maxAmount));
|
||||
|
||||
float dX = world.rand.nextFloat() * 0.8F + 0.1F;
|
||||
float dY = world.rand.nextFloat() * 0.8F + 0.1F;
|
||||
float dZ = world.rand.nextFloat() * 0.8F + 0.1F;
|
||||
EntityItem entityItem = new EntityItem(world, pos.getX() + dX, pos.getY() + dY, pos.getZ() + dZ, itemStack);
|
||||
float factor = 0.05F;
|
||||
entityItem.motionX = world.rand.nextGaussian() * factor;
|
||||
entityItem.motionY = world.rand.nextGaussian() * factor + 0.2F;
|
||||
entityItem.motionZ = world.rand.nextGaussian() * factor;
|
||||
world.spawnEntity(entityItem);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public EnumRarity getRarity(ItemStack stack) {
|
||||
return EnumRarity.EPIC;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IBlockState getStateFromMeta(int meta) {
|
||||
return this.getDefaultState().withProperty(BlockHorizontal.FACING, EnumFacing.byHorizontalIndex(meta));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMetaFromState(IBlockState state) {
|
||||
return state.getValue(BlockHorizontal.FACING).getHorizontalIndex();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected BlockStateContainer createBlockState() {
|
||||
return new BlockStateContainer(this, BlockHorizontal.FACING);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IBlockState withRotation(IBlockState state, Rotation rot) {
|
||||
return state.withProperty(BlockHorizontal.FACING, rot.rotate(state.getValue(BlockHorizontal.FACING)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public IBlockState withMirror(IBlockState state, Mirror mirror) {
|
||||
return this.withRotation(state, mirror.toRotation(state.getValue(BlockHorizontal.FACING)));
|
||||
}
|
||||
}
|
||||
//package de.ellpeck.actuallyadditions.common.blocks;
|
||||
//
|
||||
//import de.ellpeck.actuallyadditions.api.ActuallyAdditionsAPI;
|
||||
//import de.ellpeck.actuallyadditions.api.recipe.TreasureChestLoot;
|
||||
//import net.minecraft.block.Block;
|
||||
//import net.minecraft.block.BlockHorizontal;
|
||||
//import net.minecraft.block.SoundType;
|
||||
//import net.minecraft.block.material.Material;
|
||||
//import net.minecraft.block.state.BlockStateContainer;
|
||||
//import net.minecraft.block.state.IBlockState;
|
||||
//import net.minecraft.entity.EntityLivingBase;
|
||||
//import net.minecraft.entity.item.EntityItem;
|
||||
//import net.minecraft.entity.player.EntityPlayer;
|
||||
//import net.minecraft.init.Items;
|
||||
//import net.minecraft.init.SoundEvents;
|
||||
//import net.minecraft.item.EnumRarity;
|
||||
//import net.minecraft.item.Item;
|
||||
//import net.minecraft.item.ItemStack;
|
||||
//import net.minecraft.util.*;
|
||||
//import net.minecraft.util.math.BlockPos;
|
||||
//import net.minecraft.util.math.MathHelper;
|
||||
//import net.minecraft.world.World;
|
||||
//import net.minecraftforge.common.ToolType;
|
||||
//import net.minecraftforge.fml.relauncher.Side;
|
||||
//import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
//
|
||||
//import java.util.Random;
|
||||
//
|
||||
//public class BlockTreasureChest extends Block {
|
||||
//
|
||||
// public BlockTreasureChest() {
|
||||
// super(Block.Properties.create(Material.WOOD)
|
||||
// .hardnessAndResistance(300.0f, 50.0f)
|
||||
// .harvestTool(ToolType.AXE)
|
||||
// .sound(SoundType.WOOD)
|
||||
// .tickRandomly());
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// @SideOnly(Side.CLIENT)
|
||||
// public void randomDisplayTick(IBlockState state, World world, BlockPos pos, Random rand) {
|
||||
// for (int i = 0; i < 2; i++) {
|
||||
// for (float f = 0; f <= 3; f += 0.5) {
|
||||
// float particleX = rand.nextFloat();
|
||||
// float particleZ = rand.nextFloat();
|
||||
// world.spawnParticle(EnumParticleTypes.WATER_BUBBLE, (double) pos.getX() + particleX, (double) pos.getY() + f + 1, (double) pos.getZ() + particleZ, 0.0D, 0.2D, 0.0D);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public Item getItemDropped(IBlockState state, Random rand, int par3) {
|
||||
// return Items.AIR;
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, EnumFacing par6, float par7, float par8, float par9) {
|
||||
// if (!world.isRemote) {
|
||||
// world.playSound(null, pos, SoundEvents.BLOCK_CHEST_OPEN, SoundCategory.BLOCKS, 0.2F, world.rand.nextFloat() * 0.1F + 0.9F);
|
||||
// this.dropItems(world, pos);
|
||||
// world.setBlockToAir(pos);
|
||||
//
|
||||
// //TheAchievements.OPEN_TREASURE_CHEST.get(player);
|
||||
// }
|
||||
// return true;
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void onBlockPlacedBy(World world, BlockPos pos, IBlockState state, EntityLivingBase player, ItemStack stack) {
|
||||
// world.setBlockState(pos, state.withProperty(BlockHorizontal.FACING, player.getHorizontalFacing().getOpposite()), 2);
|
||||
//
|
||||
// super.onBlockPlacedBy(world, pos, state, player, stack);
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public boolean canSilkHarvest(World world, BlockPos pos, IBlockState state, EntityPlayer player) {
|
||||
// return false;
|
||||
// }
|
||||
//
|
||||
// private void dropItems(World world, BlockPos pos) {
|
||||
// for (int i = 0; i < MathHelper.getInt(world.rand, 3, 6); i++) {
|
||||
// TreasureChestLoot theReturn = WeightedRandom.getRandomItem(world.rand, ActuallyAdditionsAPI.TREASURE_CHEST_LOOT);
|
||||
// ItemStack itemStack = theReturn.returnItem.copy();
|
||||
// itemStack.setCount(MathHelper.getInt(world.rand, theReturn.minAmount, theReturn.maxAmount));
|
||||
//
|
||||
// float dX = world.rand.nextFloat() * 0.8F + 0.1F;
|
||||
// float dY = world.rand.nextFloat() * 0.8F + 0.1F;
|
||||
// float dZ = world.rand.nextFloat() * 0.8F + 0.1F;
|
||||
// EntityItem entityItem = new EntityItem(world, pos.getX() + dX, pos.getY() + dY, pos.getZ() + dZ, itemStack);
|
||||
// float factor = 0.05F;
|
||||
// entityItem.motionX = world.rand.nextGaussian() * factor;
|
||||
// entityItem.motionY = world.rand.nextGaussian() * factor + 0.2F;
|
||||
// entityItem.motionZ = world.rand.nextGaussian() * factor;
|
||||
// world.spawnEntity(entityItem);
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public EnumRarity getRarity(ItemStack stack) {
|
||||
// return EnumRarity.EPIC;
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public IBlockState getStateFromMeta(int meta) {
|
||||
// return this.getDefaultState().withProperty(BlockHorizontal.FACING, EnumFacing.byHorizontalIndex(meta));
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public int getMetaFromState(IBlockState state) {
|
||||
// return state.getValue(BlockHorizontal.FACING).getHorizontalIndex();
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// protected BlockStateContainer createBlockState() {
|
||||
// return new BlockStateContainer(this, BlockHorizontal.FACING);
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public IBlockState withRotation(IBlockState state, Rotation rot) {
|
||||
// return state.withProperty(BlockHorizontal.FACING, rot.rotate(state.getValue(BlockHorizontal.FACING)));
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public IBlockState withMirror(IBlockState state, Mirror mirror) {
|
||||
// return this.withRotation(state, mirror.toRotation(state.getValue(BlockHorizontal.FACING)));
|
||||
// }
|
||||
//}
|
||||
|
|
|
@ -1,87 +1,69 @@
|
|||
package de.ellpeck.actuallyadditions.common.blocks;
|
||||
|
||||
import de.ellpeck.actuallyadditions.common.ActuallyAdditions;
|
||||
import de.ellpeck.actuallyadditions.common.blocks.base.BlockContainerBase;
|
||||
import de.ellpeck.actuallyadditions.common.inventory.GuiHandler;
|
||||
import de.ellpeck.actuallyadditions.common.tile.TileEntityXPSolidifier;
|
||||
import net.minecraft.block.BlockHorizontal;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.block.SoundType;
|
||||
import net.minecraft.block.material.Material;
|
||||
import net.minecraft.block.state.BlockStateContainer;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.EnumRarity;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.item.BlockItemUseContext;
|
||||
import net.minecraft.state.DirectionProperty;
|
||||
import net.minecraft.state.StateContainer;
|
||||
import net.minecraft.state.properties.BlockStateProperties;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.EnumHand;
|
||||
import net.minecraft.util.Mirror;
|
||||
import net.minecraft.util.Rotation;
|
||||
import net.minecraft.util.ActionResultType;
|
||||
import net.minecraft.util.Direction;
|
||||
import net.minecraft.util.Hand;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.BlockRayTraceResult;
|
||||
import net.minecraft.world.IBlockReader;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.ToolType;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
public class BlockXPSolidifier extends BlockContainerBase {
|
||||
public static final DirectionProperty FACING = BlockStateProperties.HORIZONTAL_FACING;
|
||||
|
||||
public BlockXPSolidifier() {
|
||||
super(Properties.create(Material.ROCK)
|
||||
.hardnessAndResistance(2.5f, 10.0f)
|
||||
.harvestTool(ToolType.PICKAXE)
|
||||
.sound(SoundType.STONE));
|
||||
|
||||
setDefaultState(getStateContainer().getBaseState().with(FACING, Direction.SOUTH));
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public TileEntity createNewTileEntity(World world, int par2) {
|
||||
public TileEntity createTileEntity(BlockState state, IBlockReader world) {
|
||||
return new TileEntityXPSolidifier();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, EnumFacing par6, float par7, float par8, float par9) {
|
||||
public ActionResultType onBlockActivated(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand handIn, BlockRayTraceResult hit) {
|
||||
if (!world.isRemote) {
|
||||
TileEntityXPSolidifier solidifier = (TileEntityXPSolidifier) world.getTileEntity(pos);
|
||||
if (solidifier != null) {
|
||||
player.openGui(ActuallyAdditions.INSTANCE, GuiHandler.GuiTypes.XP_SOLIDIFIER.ordinal(), world, pos.getX(), pos.getY(), pos.getZ());
|
||||
// todo: add back
|
||||
// player.openGui(ActuallyAdditions.INSTANCE, GuiHandler.GuiTypes.XP_SOLIDIFIER.ordinal(), world, pos.getX(), pos.getY(), pos.getZ());
|
||||
return ActionResultType.SUCCESS;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return true;
|
||||
|
||||
return super.onBlockActivated(state, world, pos, player, handIn, hit);
|
||||
}
|
||||
|
||||
@Override
|
||||
public EnumRarity getRarity(ItemStack stack) {
|
||||
return EnumRarity.EPIC;
|
||||
protected void fillStateContainer(StateContainer.Builder<Block, BlockState> builder) {
|
||||
super.fillStateContainer(builder);
|
||||
builder.add(FACING);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public void onBlockPlacedBy(World world, BlockPos pos, IBlockState state, EntityLivingBase player, ItemStack stack) {
|
||||
world.setBlockState(pos, state.withProperty(BlockHorizontal.FACING, player.getHorizontalFacing().getOpposite()), 2);
|
||||
|
||||
super.onBlockPlacedBy(world, pos, state, player, stack);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IBlockState getStateFromMeta(int meta) {
|
||||
return this.getDefaultState().withProperty(BlockHorizontal.FACING, EnumFacing.byHorizontalIndex(meta));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMetaFromState(IBlockState state) {
|
||||
return state.getValue(BlockHorizontal.FACING).getHorizontalIndex();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected BlockStateContainer createBlockState() {
|
||||
return new BlockStateContainer(this, BlockHorizontal.FACING);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IBlockState withRotation(IBlockState state, Rotation rot) {
|
||||
return state.withProperty(BlockHorizontal.FACING, rot.rotate(state.getValue(BlockHorizontal.FACING)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public IBlockState withMirror(IBlockState state, Mirror mirror) {
|
||||
return this.withRotation(state, mirror.toRotation(state.getValue(BlockHorizontal.FACING)));
|
||||
public BlockState getStateForPlacement(BlockItemUseContext context) {
|
||||
return getDefaultState().with(FACING, context.getPlacementHorizontalFacing().getOpposite());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -206,8 +206,9 @@ public final class InitBlocks {
|
|||
public static final RegistryObject<Block> blockCoffee
|
||||
= BLOCKS.register("block_coffee", () -> new BlockPlant(2, 2));
|
||||
|
||||
public static final RegistryObject<Block> blockCompost
|
||||
= BLOCKS.register("block_compost", BlockCompost::new);
|
||||
// this isn't needed any more
|
||||
// public static final RegistryObject<Block> blockCompost
|
||||
// = BLOCKS.register("block_compost", BlockCompost::new);
|
||||
|
||||
public static final RegistryObject<Block> blockMisc
|
||||
= BLOCKS.register("block_misc", BlockMisc::new);
|
||||
|
@ -215,6 +216,7 @@ public final class InitBlocks {
|
|||
public static final RegistryObject<Block> blockFeeder
|
||||
= BLOCKS.register("block_feeder", BlockFeeder::new);
|
||||
|
||||
// this isn't needed anymore
|
||||
// public static final RegistryObject<Block> blockGiantChest
|
||||
// = BLOCKS.register("block_giant_chest", BlockGiantChest::new);
|
||||
//
|
||||
|
|
Loading…
Reference in a new issue