1.12: Backported E-Furnace/Labeled Crate from 1.14/1.15.

This commit is contained in:
stfwi 2020-03-21 18:00:37 +01:00
parent 27a957ba8d
commit 41b48208a0
55 changed files with 2556 additions and 34 deletions

View file

@ -4,4 +4,4 @@ org.gradle.jvmargs=-Xmx8G
version_minecraft=1.12.2
version_forge=14.23.5.2768
version_jei=4.10.0.198
version_engineersdecor=1.0.20-b1
version_engineersdecor=1.0.20-b2

View file

@ -1,6 +1,8 @@
{
"homepage": "https://www.curseforge.com/minecraft/mc-mods/engineers-decor/",
"1.12.2": {
"1.0.20-b2": "[A] Backported Electrical Furnace GUI speed selection switch.\n[A] Backported Labeled Crate (storage crate with built-in item frame).",
"1.0.20-b1": "[/] Version skipped for 1.12.2.",
"1.0.19": "[R] Release based on v1.0.19-b4. Release-to-release changes: * Transfer fixes for Tree Cutter / Block Breaker, and Factory hopper. * Cleanups, feature backports * Visual fixes and improvements\n[A] Backport of status display for Tree Cutter, Block Breaker and Solar Panel.",
"1.0.19-b4": "[A] Creative tab opt-out visibility handling added (issue #90, thx pimalel233).",
"1.0.19-b3": "[A] Factory Hopper: Added bottom item handler (CR#227).",
@ -82,6 +84,6 @@
},
"promos": {
"1.12.2-recommended": "1.0.19",
"1.12.2-latest": "1.0.19"
"1.12.2-latest": "1.0.20-b2"
}
}

View file

@ -10,7 +10,10 @@ Mod sources for Minecraft version 1.12.2.
----
## Version history
~ v1.0.20-b1 [F]
- v1.0.20-b2 [A] Backported Electrical Furnace GUI speed selection switch.
[A] Backported Labeled Crate (storage crate with built-in item frame).
- v1.0.20-b1 [/] Version skipped for 1.12.2.
-------------------------------------------------------------------
- v1.0.19 [R] Release based on v1.0.19-b4. Release-to-release changes:

View file

@ -210,6 +210,13 @@ public class ModContent
ModAuxiliaries.getPixeledAABB(0,0,0, 16,16,16)
);
public static final BlockDecorLabeledCrate.DecorLabeledCrateBlock LABELED_CRATE = new BlockDecorLabeledCrate.DecorLabeledCrateBlock(
"labeled_crate",
BlockDecor.CFG_CUTOUT|BlockDecor.CFG_HORIZIONTAL|BlockDecor.CFG_LOOK_PLACEMENT|BlockDecor.CFG_OPPOSITE_PLACEMENT,
Material.WOOD, 0.5f, 128f, SoundType.METAL,
ModAuxiliaries.getPixeledAABB(0,0,0, 16,16,16)
);
//--------------------------------------------------------------------------------------------------------------------
public static final BlockDecorStraightPole TREATED_WOOD_POLE = new BlockDecorStraightPole(
@ -478,6 +485,9 @@ public class ModContent
private static final TileEntityRegistrationData TREATED_WOOD_CRAFTING_TABLE_TEI = new TileEntityRegistrationData(
BlockDecorCraftingTable.BTileEntity.class, "te_crafting_table"
);
private static final TileEntityRegistrationData LABELED_CRATE_TEI = new TileEntityRegistrationData(
BlockDecorLabeledCrate.LabeledCrateTileEntity.class, "te_labeled_crate"
);
private static final TileEntityRegistrationData SMALL_LAB_FURNACE_TEI = new TileEntityRegistrationData(
BlockDecorFurnace.BTileEntity.class, "te_small_lab_furnace"
);
@ -530,6 +540,7 @@ public class ModContent
private static final Object content[] = {
TREATED_WOOD_CRAFTING_TABLE, TREATED_WOOD_CRAFTING_TABLE_TEI,
LABELED_CRATE, LABELED_CRATE_TEI,
SMALL_LAB_FURNACE, SMALL_LAB_FURNACE_TEI,
SMALL_ELECTRICAL_FURNACE, SMALL_ELECTRICAL_FURNACE_TEI,
FACTORY_HOPPER,FACTORY_HOPPER_TEI,
@ -704,6 +715,9 @@ public class ModContent
if(!ModConfig.isOptedOut(TREATED_WOOD_CRAFTING_TABLE)) {
ClientRegistry.bindTileEntitySpecialRenderer(BlockDecorCraftingTable.BTileEntity.class, new ModTesrs.TesrDecorCraftingTable());
}
if(!ModConfig.isOptedOut(LABELED_CRATE)) {
ClientRegistry.bindTileEntitySpecialRenderer(BlockDecorLabeledCrate.LabeledCrateTileEntity.class, new ModTesrs.TesrDecorLabeledCrate());
}
if(!ModConfig.isOptedOut(TEST_BLOCK)) {
ClientRegistry.bindTileEntitySpecialRenderer(BlockDecorTest.BTileEntity.class, new ModTesrs.TesrDecorTest());
}

View file

@ -161,6 +161,7 @@ public class ModEngineersDecor
public static final int GUIID_FACTORY_DROPPER = 213105;
public static final int GUIID_FACTORY_HOPPER = 213106;
public static final int GUIID_FACTORY_PLACER = 213107;
public static final int GUIID_LABELED_CRATE = 213108;
@Override
public Object getServerGuiElement(final int guiid, final EntityPlayer player, final World world, int x, int y, int z)
@ -175,6 +176,7 @@ public class ModEngineersDecor
case GUIID_FACTORY_DROPPER: return BlockDecorDropper.getServerGuiElement(player, world, pos, te);
case GUIID_FACTORY_HOPPER: return BlockDecorHopper.getServerGuiElement(player, world, pos, te);
case GUIID_FACTORY_PLACER: return BlockDecorPlacer.getServerGuiElement(player, world, pos, te);
case GUIID_LABELED_CRATE: return BlockDecorLabeledCrate.getServerGuiElement(player, world, pos, te);
}
return null;
}
@ -193,6 +195,7 @@ public class ModEngineersDecor
case GUIID_FACTORY_DROPPER: return BlockDecorDropper.getClientGuiElement(player, world, pos, te);
case GUIID_FACTORY_HOPPER: return BlockDecorHopper.getClientGuiElement(player, world, pos, te);
case GUIID_FACTORY_PLACER: return BlockDecorPlacer.getClientGuiElement(player, world, pos, te);
case GUIID_LABELED_CRATE: return BlockDecorLabeledCrate.getClientGuiElement(player, world, pos, te);
}
return null;
}

View file

@ -38,9 +38,11 @@ import net.minecraftforge.items.IItemHandler;
import net.minecraftforge.items.ItemHandlerHelper;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import wile.engineersdecor.detail.Networking;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.io.IOException;
import java.util.Random;
public class BlockDecorFurnaceElectrical extends BlockDecorFurnace
@ -134,6 +136,13 @@ public class BlockDecorFurnaceElectrical extends BlockDecorFurnace
drawTexturedModalRect(x0+79, y0+30, 176, 15, 1+progress_px(17), 15);
int we = energy_px(32, 8);
if(we>0) drawTexturedModalRect(x0+88, y0+53, 185, 30, we, 13);
switch(te.getField(4)) {
case 0: drawTexturedModalRect(x0+144, y0+57, 180, 57, 6, 9); break;
case 1: drawTexturedModalRect(x0+142, y0+58, 190, 58, 9, 6); break;
case 2: drawTexturedModalRect(x0+144, y0+56, 200, 57, 6, 9); break;
case 3: drawTexturedModalRect(x0+143, y0+58, 210, 58, 9, 6); break;
default: break;
}
}
private int progress_px(int pixels)
@ -153,10 +162,33 @@ public class BlockDecorFurnaceElectrical extends BlockDecorFurnace
return k;
}
@Override
protected void mouseClicked(int mouseX, int mouseY, int mouseButton) throws IOException
{
BContainer container = (BContainer)inventorySlots;
int mx = (int)(mouseX - getGuiLeft() + .5), my = (int)(mouseY - getGuiTop() + .5);
int speed = -1;
if((!isPointInRegion(136, 48, 28, 28, mouseX, mouseY))) {
super.mouseClicked(mouseX, mouseY, mouseButton);
} else if(isPointInRegion(144, 64, 6, 10, mouseX, mouseY)) {
speed = 0;
} else if(isPointInRegion(134, 58, 10, 6, mouseX, mouseY)) {
speed = 1;
} else if(isPointInRegion(144, 48, 6, 10, mouseX, mouseY)) {
speed = 2;
} else if(isPointInRegion(150, 58, 10, 6, mouseX, mouseY)) {
speed = 3;
}
if(speed >= 0) {
NBTTagCompound nbt = new NBTTagCompound();
nbt.setInteger("speed", speed);
Networking.PacketTileNotify.sendToServer(te, nbt);
}
}
}
//--------------------------------------------------------------------------------------------------------------------
// container
// Container
//--------------------------------------------------------------------------------------------------------------------
public static class BContainer extends Container
@ -274,7 +306,7 @@ public class BlockDecorFurnaceElectrical extends BlockDecorFurnace
// Tile entity
//--------------------------------------------------------------------------------------------------------------------
public static class BTileEntity extends BlockDecorFurnace.BTileEntity implements ITickable, ISidedInventory, IEnergyStorage
public static class BTileEntity extends BlockDecorFurnace.BTileEntity implements ITickable, ISidedInventory, IEnergyStorage, Networking.IPacketReceiver
{
public static final int TICK_INTERVAL = 4;
public static final int FIFO_INTERVAL = 20;
@ -295,16 +327,12 @@ public class BlockDecorFurnaceElectrical extends BlockDecorFurnace
public static final int DEFAULT_ENERGY_CONSUMPTION = 16 ;
public static final int DEFAULT_SCALED_ENERGY_CONSUMPTION = DEFAULT_ENERGY_CONSUMPTION * HEAT_INCREMENT * DEFAULT_SPEED_PERCENT/100;
// Config ----------------------------------------------------------------------------------
private static int energy_consumption_ = DEFAULT_SCALED_ENERGY_CONSUMPTION;
private static int transfer_energy_consumption_ = DEFAULT_SCALED_ENERGY_CONSUMPTION/8;
private static int proc_speed_percent_ = DEFAULT_SPEED_PERCENT;
private int burntime_left_;
private int proc_time_elapsed_;
private int proc_time_needed_;
private int energy_stored_;
private int speed_;
private int tick_timer_;
private int fifo_timer_;
private static double speed_setting_factor_[] = {0.0, 1.0, 1.5, 2.0};
public static void on_config(int speed_percent, int standard_energy_per_tick)
{
@ -314,6 +342,17 @@ public class BlockDecorFurnaceElectrical extends BlockDecorFurnace
ModEngineersDecor.logger.info("Config electrical furnace speed:" + proc_speed_percent_ + ", power consumption:" + energy_consumption_);
}
// BTileEntity ------------------------------------------------------------------------------
private int burntime_left_;
private int proc_time_elapsed_;
private int proc_time_needed_;
private int energy_stored_;
private int speed_;
private int tick_timer_;
private int fifo_timer_;
private boolean enabled_ = false;
public BTileEntity()
{ super(); reset(); }
@ -326,7 +365,7 @@ public class BlockDecorFurnaceElectrical extends BlockDecorFurnace
fifo_timer_ = 0;
tick_timer_ = 0;
energy_stored_= 0;
speed_ = 0;
speed_ = 1;
}
public void readnbt(NBTTagCompound compound)
@ -339,6 +378,7 @@ public class BlockDecorFurnaceElectrical extends BlockDecorFurnace
proc_time_needed_ = compound.getInteger("CookTimeTotal");
energy_stored_ = compound.getInteger("Energy");
speed_ = compound.getInteger("SpeedSetting");
speed_ = (speed_ < 0) ? (1) : ((speed_>3) ? 3 : speed_);
}
protected void writenbt(NBTTagCompound compound)
@ -602,6 +642,19 @@ public class BlockDecorFurnaceElectrical extends BlockDecorFurnace
return super.getCapability(capability, facing);
}
// IPacketReceiver -------------------------------------------------------------------------------
@Override
public void onServerPacketReceived(NBTTagCompound nbt)
{}
@Override
public void onClientPacketReceived(EntityPlayer player, NBTTagCompound nbt)
{
if(nbt.hasKey("speed")) speed_ = MathHelper.clamp(nbt.getInteger("speed"), 0, 3);
markDirty();
}
// ITickable ------------------------------------------------------------------------------------
private boolean adjacent_inventory_shift(boolean inp, boolean out)
@ -646,14 +699,24 @@ public class BlockDecorFurnaceElectrical extends BlockDecorFurnace
// returns TE dirty
private boolean heat_up()
{
if(energy_stored_ < (energy_consumption_)) return false;
if(energy_stored_ < (energy_consumption())) return false;
if(burntime_left_ >= (HEAT_CAPACITY-HEAT_INCREMENT)) return false;
energy_stored_ -= energy_consumption_;
energy_stored_ -= energy_consumption();
burntime_left_ += HEAT_INCREMENT;
this.markDirty();
return true;
}
int energy_consumption()
{
switch(speed_) {
case 1: return energy_consumption_;
case 2: return energy_consumption_ * 2;
case 3: return energy_consumption_ * 4;
default: return 0;
}
}
private void sync_blockstate()
{
final IBlockState state = world.getBlockState(pos);
@ -682,9 +745,14 @@ public class BlockDecorFurnaceElectrical extends BlockDecorFurnace
if(transferItems(FIFO_INPUT_0_SLOT_NO, SMELTING_INPUT_SLOT_NO, 64)) dirty = true;
if(transferItems(FIFO_INPUT_1_SLOT_NO, FIFO_INPUT_0_SLOT_NO, 64)) { dirty = true; } else { shift_in = true; }
}
if(energy_stored_ < energy_consumption()) {
enabled_ = false;
} else if(energy_stored_ >= (MAX_ENERGY_BUFFER/2)) {
enabled_ = true;
}
final ItemStack last_inp_stack = current_smelting_input_stack_;
current_smelting_input_stack_ = stacks_.get(SMELTING_INPUT_SLOT_NO);
if((!current_smelting_input_stack_.isEmpty()) && (energy_stored_ >= energy_consumption_)) {
if((!current_smelting_input_stack_.isEmpty()) && (enabled_) && (speed_>0) && (speed_<4)) {
if(!current_smelting_input_stack_.isItemEqual(current_smelting_input_stack_)) {
proc_time_elapsed_ = 0;
proc_time_needed_ = getCookTime(current_smelting_input_stack_);
@ -700,7 +768,7 @@ public class BlockDecorFurnaceElectrical extends BlockDecorFurnace
}
if(isBurning() && can_smelt) {
if(heat_up()) dirty = true;
proc_time_elapsed_ += (TICK_INTERVAL * proc_speed_percent_/100);
proc_time_elapsed_ += (TICK_INTERVAL * proc_speed_percent_ * speed_setting_factor_[speed_] / 100);
if(proc_time_elapsed_ >= proc_time_needed_) {
proc_time_elapsed_ = 0;
proc_time_needed_ = getCookTime(current_smelting_input_stack_);

View file

@ -0,0 +1,593 @@
/*
* @file BlockDecorLabeledCrate.java
* @author Stefan Wilhelm (wile)
* @copyright (C) 2019 Stefan Wilhelm
* @license MIT (see https://opensource.org/licenses/MIT)
*
* Storage crate with a content hint.
*/
package wile.engineersdecor.blocks;
import net.minecraft.block.Block;
import net.minecraft.block.SoundType;
import net.minecraft.block.material.Material;
import net.minecraft.block.state.IBlockState;
import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.*;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.network.NetworkManager;
import net.minecraft.network.play.server.SPacketUpdateTileEntity;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumHand;
import net.minecraft.util.NonNullList;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.text.ITextComponent;
import net.minecraft.util.text.TextComponentTranslation;
import net.minecraft.world.Explosion;
import net.minecraft.world.World;
import net.minecraftforge.common.capabilities.Capability;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import net.minecraftforge.items.CapabilityItemHandler;
import net.minecraftforge.items.IItemHandler;
import net.minecraftforge.items.ItemHandlerHelper;
import wile.engineersdecor.ModEngineersDecor;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
public class BlockDecorLabeledCrate
{
public static void on_config(int stack_limit)
{
}
//--------------------------------------------------------------------------------------------------------------------
// Block
//--------------------------------------------------------------------------------------------------------------------
public static class DecorLabeledCrateBlock extends BlockDecorDirectedHorizontal
{
public DecorLabeledCrateBlock(@Nonnull String registryName, long config, @Nullable Material material, float hardness, float resistance, @Nullable SoundType sound, @Nonnull AxisAlignedBB unrotatedAABB)
{ super(registryName, config, material, hardness, resistance, sound, unrotatedAABB); }
@Override
public boolean hasTileEntity(IBlockState state)
{ return true; }
@Override
@Nullable
public TileEntity createTileEntity(World world, IBlockState state)
{ return new LabeledCrateTileEntity(); }
@Override
public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ)
{
if(world.isRemote) return true;
player.openGui(ModEngineersDecor.instance, ModEngineersDecor.GuiHandler.GUIID_LABELED_CRATE, world, pos.getX(), pos.getY(), pos.getZ());
return true;
}
@Override
public void onBlockPlacedBy(World world, BlockPos pos, IBlockState state, EntityLivingBase placer, ItemStack stack)
{
if(world.isRemote) return;
if((!stack.hasTagCompound()) || (!stack.getTagCompound().hasKey("inventory"))) return;
NBTTagCompound inventory_nbt = stack.getTagCompound().getCompoundTag("inventory");
if(inventory_nbt.isEmpty()) return;
final TileEntity te = world.getTileEntity(pos);
if(!(te instanceof LabeledCrateTileEntity)) return;
((LabeledCrateTileEntity)te).readnbt(inventory_nbt);
((LabeledCrateTileEntity)te).markDirty();
}
private ItemStack itemize_with_inventory(World world, BlockPos pos)
{
TileEntity te = world.getTileEntity(pos);
if(!(te instanceof LabeledCrateTileEntity)) return ItemStack.EMPTY;
ItemStack stack = new ItemStack(this, 1);
NBTTagCompound inventory_nbt = new NBTTagCompound();
ItemStackHelper.saveAllItems(inventory_nbt, ((LabeledCrateTileEntity)te).stacks_, false);
if(!inventory_nbt.isEmpty()) {
NBTTagCompound nbt = new NBTTagCompound();
nbt.setTag("inventory", inventory_nbt);
stack.setTagCompound(nbt);
}
return stack;
}
@Override
public boolean removedByPlayer(IBlockState state, World world, BlockPos pos, EntityPlayer player, boolean willHarvest)
{
if(world.isRemote) return true;
final ItemStack stack = itemize_with_inventory(world, pos);
if(stack != ItemStack.EMPTY) {
world.spawnEntity(new EntityItem(world, pos.getX()+0.5, pos.getY()+0.5, pos.getZ()+0.5, stack));
world.setBlockToAir(pos);
world.removeTileEntity(pos);
return false;
} else {
return super.removedByPlayer(state, world, pos, player, willHarvest);
}
}
@Override
public void onBlockExploded(World world, BlockPos pos, Explosion explosion)
{
if(world.isRemote) return;
TileEntity te = world.getTileEntity(pos);
if(!(te instanceof LabeledCrateTileEntity)) return;
for(ItemStack stack: ((LabeledCrateTileEntity)te).stacks_) {
if(!stack.isEmpty()) world.spawnEntity(new EntityItem(world, pos.getX(), pos.getY(), pos.getZ(), stack));
}
((LabeledCrateTileEntity)te).reset();
super.onBlockExploded(world, pos, explosion);
}
@Override
@SuppressWarnings("deprecation")
public boolean hasComparatorInputOverride(IBlockState state)
{ return true; }
@Override
@SuppressWarnings("deprecation")
public int getComparatorInputOverride(IBlockState blockState, World world, BlockPos pos)
{ return Container.calcRedstone(world.getTileEntity(pos)); }
}
//--------------------------------------------------------------------------------------------------------------------
// Tile entity
//--------------------------------------------------------------------------------------------------------------------
public static class LabeledCrateTileEntity extends TileEntity implements ISidedInventory
{
public static final int NUM_OF_FIELDS = 1;
public static final int NUM_OF_SLOTS = 55;
public static final int ITEMFRAME_SLOTNO = 54;
// LabeledCrateTileEntity --------------------------------------------------------------------------
protected NonNullList<ItemStack> stacks_ = NonNullList.<ItemStack>withSize(NUM_OF_SLOTS, ItemStack.EMPTY);
public LabeledCrateTileEntity()
{ reset(); }
protected void reset()
{ stacks_ = NonNullList.<ItemStack>withSize(NUM_OF_SLOTS, ItemStack.EMPTY); }
public void readnbt(NBTTagCompound compound)
{
NonNullList<ItemStack> stacks = NonNullList.<ItemStack>withSize(NUM_OF_SLOTS, ItemStack.EMPTY);
ItemStackHelper.loadAllItems(compound, stacks);
while(stacks.size() < NUM_OF_SLOTS) stacks.add(ItemStack.EMPTY);
stacks_ = stacks;
}
protected void writenbt(NBTTagCompound compound)
{ ItemStackHelper.saveAllItems(compound, stacks_); }
public ItemStack getItemFrameStack()
{ return (stacks_.size() > ITEMFRAME_SLOTNO)?(stacks_.get(ITEMFRAME_SLOTNO)):(ItemStack.EMPTY); }
// TileEntity ------------------------------------------------------------------------------
@Override
public boolean shouldRefresh(World world, BlockPos pos, IBlockState os, IBlockState ns)
{ return (os.getBlock()!=ns.getBlock())||(!(ns.getBlock() instanceof DecorLabeledCrateBlock));}
@Override
public void readFromNBT(NBTTagCompound compound)
{ super.readFromNBT(compound); readnbt(compound); }
@Override
public NBTTagCompound writeToNBT(NBTTagCompound compound)
{ super.writeToNBT(compound); writenbt(compound); return compound; }
@Override
public NBTTagCompound getUpdateTag()
{ NBTTagCompound nbt = super.getUpdateTag(); writenbt(nbt); return nbt; }
@Override
@Nullable
public SPacketUpdateTileEntity getUpdatePacket()
{ return new SPacketUpdateTileEntity(pos, 1, getUpdateTag()); }
@Override
public void onDataPacket(NetworkManager net, SPacketUpdateTileEntity pkt) // on client
{ super.readFromNBT(pkt.getNbtCompound()); readnbt(pkt.getNbtCompound()); super.onDataPacket(net, pkt); }
@Override
public void handleUpdateTag(NBTTagCompound tag) // on client
{ readFromNBT(tag); }
// INameable ---------------------------------------------------------------------------
@Override
public String getName()
{ final Block block = getBlockType(); return (block!=null)?(block.getTranslationKey()+".name"):(""); }
@Override
public boolean hasCustomName()
{ return false; }
@Override
public ITextComponent getDisplayName()
{ return new TextComponentTranslation(getName(), new Object[0]); }
// IInventory ------------------------------------------------------------------------------
@Override
public int getSizeInventory()
{ return stacks_.size(); }
@Override
public boolean isEmpty()
{ for(ItemStack stack : stacks_) { if(!stack.isEmpty()) return false; } return true; }
@Override
public ItemStack getStackInSlot(int index)
{ return ((index >= 0)&&(index < getSizeInventory()))?stacks_.get(index):ItemStack.EMPTY; }
@Override
public ItemStack decrStackSize(int index, int count)
{ return ItemStackHelper.getAndSplit(stacks_, index, count); }
@Override
public ItemStack removeStackFromSlot(int index)
{ return ItemStackHelper.getAndRemove(stacks_, index); }
@Override
public void setInventorySlotContents(int index, ItemStack stack)
{
if(stack.getCount() > getInventoryStackLimit()) stack.setCount(getInventoryStackLimit());
stacks_.set(index, stack);
markDirty();
if(!getWorld().isRemote) {
// This should result in sending TE data (getUpdateTag etc) to the client for the TER.
IBlockState state = world.getBlockState(getPos());
getWorld().notifyBlockUpdate(getPos(), state, state, 2|16|32);
}
}
@Override
public int getInventoryStackLimit()
{ return 64; }
@Override
public void markDirty()
{ super.markDirty(); }
@Override
public boolean isUsableByPlayer(EntityPlayer player)
{ return getPos().distanceSq(player.getPosition()) < 36; }
@Override
public void openInventory(EntityPlayer player)
{}
@Override
public void closeInventory(EntityPlayer player)
{ markDirty(); }
@Override
public boolean isItemValidForSlot(int index, ItemStack stack)
{ return (index!=ITEMFRAME_SLOTNO); }
@Override
public void clear()
{ stacks_.clear(); }
// Fields -----------------------------------------------------------------------------------------------
@Override
public int getField(int id)
{ return 0; }
@Override
public void setField(int id, int value)
{}
@Override
public int getFieldCount()
{ return 0; }
// ISidedInventory ----------------------------------------------------------------------------
private static final int[] SIDED_INV_SLOTS;
static {
SIDED_INV_SLOTS = new int[LabeledCrateTileEntity.NUM_OF_SLOTS-1];
for(int i = 0; i < SIDED_INV_SLOTS.length; ++i) SIDED_INV_SLOTS[i] = i;
}
@Override
public int[] getSlotsForFace(EnumFacing side)
{ return SIDED_INV_SLOTS; }
@Override
public boolean canInsertItem(int index, ItemStack stack, EnumFacing direction)
{ return true; }
@Override
public boolean canExtractItem(int index, ItemStack stack, EnumFacing direction)
{ return true; }
// IItemHandler --------------------------------------------------------------------------------
protected static class BItemHandler implements IItemHandler
{
private LabeledCrateTileEntity te;
BItemHandler(LabeledCrateTileEntity te)
{
this.te = te;
}
@Override
public int getSlots()
{
return ITEMFRAME_SLOTNO;
} // iframe slot is the last
@Override
public int getSlotLimit(int index)
{
return te.getInventoryStackLimit();
}
@Override
public boolean isItemValid(int slot, @Nonnull ItemStack stack)
{
return true;
}
@Override
@Nonnull
public ItemStack insertItem(int slotno, @Nonnull ItemStack stack, boolean simulate)
{
if(stack.isEmpty()) return ItemStack.EMPTY;
if((slotno < 0)||((slotno >= NUM_OF_SLOTS))||((slotno==ITEMFRAME_SLOTNO))) return ItemStack.EMPTY;
ItemStack slotstack = getStackInSlot(slotno);
if(!slotstack.isEmpty()) {
if(slotstack.getCount() >= Math.min(slotstack.getMaxStackSize(), getSlotLimit(slotno))) return stack;
if(!ItemHandlerHelper.canItemStacksStack(stack, slotstack)) return stack;
if(!te.canInsertItem(slotno, stack, EnumFacing.UP)||(!te.isItemValidForSlot(slotno, stack))) return stack;
int n = Math.min(stack.getMaxStackSize(), getSlotLimit(slotno))-slotstack.getCount();
if(stack.getCount() <= n) {
if(!simulate) {
ItemStack copy = stack.copy();
copy.grow(slotstack.getCount());
te.setInventorySlotContents(slotno, copy);
}
return ItemStack.EMPTY;
}
else {
stack = stack.copy();
if(!simulate) {
ItemStack copy = stack.splitStack(n);
copy.grow(slotstack.getCount());
te.setInventorySlotContents(slotno, copy);
return stack;
}
else {
stack.shrink(n);
return stack;
}
}
}
else {
if(!te.canInsertItem(slotno, stack, EnumFacing.UP)||(!te.isItemValidForSlot(slotno, stack))) return stack;
int n = Math.min(stack.getMaxStackSize(), getSlotLimit(slotno));
if(n < stack.getCount()) {
stack = stack.copy();
if(!simulate) {
te.setInventorySlotContents(slotno, stack.splitStack(n));
return stack;
}
else {
stack.shrink(n);
return stack;
}
}
else {
if(!simulate) te.setInventorySlotContents(slotno, stack);
return ItemStack.EMPTY;
}
}
}
@Override
@Nonnull
public ItemStack extractItem(int index, int amount, boolean simulate)
{
if((index < 0)||((index >= NUM_OF_SLOTS))||((index==ITEMFRAME_SLOTNO))) return ItemStack.EMPTY;
if(!simulate) return ItemStackHelper.getAndSplit(te.stacks_, index, amount);
ItemStack stack = te.stacks_.get(index).copy();
if(stack.getCount() > amount) stack.setCount(amount);
return stack;
}
@Override
@Nonnull
public ItemStack getStackInSlot(int index)
{
return te.getStackInSlot(index);
}
}
// Capability export ----------------------------------------------------------------------------
private final IItemHandler item_handler_ = new BItemHandler(this);
@Override
public boolean hasCapability(Capability<?> cap, EnumFacing facing)
{
return (cap==CapabilityItemHandler.ITEM_HANDLER_CAPABILITY)||super.hasCapability(cap, facing);
}
@Override
@SuppressWarnings("unchecked")
@Nullable
public <T> T getCapability(Capability<T> capability, @Nullable EnumFacing facing)
{
if(capability==CapabilityItemHandler.ITEM_HANDLER_CAPABILITY) return (T)item_handler_;
return super.getCapability(capability, facing);
}
}
//--------------------------------------------------------------------------------------------------------------------
// GUI
//--------------------------------------------------------------------------------------------------------------------
@SideOnly(Side.CLIENT)
private static class BGui extends GuiContainer
{
private final LabeledCrateTileEntity te;
public BGui(InventoryPlayer playerInventory, World world, BlockPos pos, LabeledCrateTileEntity te)
{
super(new BContainer(playerInventory, world, pos, te));
this.te = te;
xSize = 213;
ySize = 206;
}
@Override
public void initGui()
{ super.initGui(); }
@Override
public void drawScreen(int mouseX, int mouseY, float partialTicks)
{
drawDefaultBackground();
super.drawScreen(mouseX, mouseY, partialTicks);
renderHoveredToolTip(mouseX, mouseY);
}
@Override
protected void drawGuiContainerBackgroundLayer(float partialTicks, int mouseX, int mouseY)
{
GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
mc.getTextureManager().bindTexture(new ResourceLocation(ModEngineersDecor.MODID, "textures/gui/labeled_crate_gui.png"));
final int x0=guiLeft, y0=guiTop, w=xSize, h=ySize;
drawTexturedModalRect(x0, y0, 0, 0, w, h);
}
}
//--------------------------------------------------------------------------------------------------------------------
// Container
//--------------------------------------------------------------------------------------------------------------------
public static class BContainer extends Container
{
//------------------------------------------------------------------------------------------------------------------
private static final int PLAYER_INV_START_SLOTNO = LabeledCrateTileEntity.NUM_OF_SLOTS;
private final World world;
private final BlockPos pos;
private final EntityPlayer player;
private final LabeledCrateTileEntity te;
//------------------------------------------------------------------------------------------------------------------
public BContainer(InventoryPlayer playerInventory, World world, BlockPos pos, LabeledCrateTileEntity te)
{
this.player = playerInventory.player;
this.world = world;
this.pos = pos;
this.te = te;
int i=-1;
// storage slots (stacks 0 to 53)
for(int y=0; y<6; ++y) {
for(int x=0; x<9; ++x) {
int xpos = 28+x*18, ypos = 10+y*18;
addSlotToContainer(new Slot(te, ++i, xpos, ypos));
}
}
// picture frame slot (54)
addSlotToContainer(new Slot(te, ++i, 191, 100) {
@Override public int getSlotStackLimit(){return 1;}
});
// player slots
for(int x=0; x<9; ++x) {
addSlotToContainer(new Slot(playerInventory, x, 28+x*18, 183)); // player slots: 0..8
}
for(int y=0; y<3; ++y) {
for(int x=0; x<9; ++x) {
addSlotToContainer(new Slot(playerInventory, x+y*9+9, 28+x*18, 125+y*18)); // player slots: 9..35
}
}
}
@Override
public void addListener(IContainerListener listener)
{ super.addListener(listener); listener.sendAllWindowProperties(this, te); }
@Override
public void detectAndSendChanges()
{ super.detectAndSendChanges(); }
@Override
@SideOnly(Side.CLIENT)
public void updateProgressBar(int id, int data)
{ te.setField(id, data); }
@Override
public boolean canInteractWith(EntityPlayer player)
{ return (world.getBlockState(pos).getBlock() instanceof DecorLabeledCrateBlock) && (player.getDistanceSq(pos) <= 64); }
@Override
public boolean canMergeSlot(ItemStack stack, Slot slot)
{ return (slot.getSlotStackLimit() > 1); }
@Override
public void onContainerClosed(EntityPlayer player)
{ super.onContainerClosed(player); }
@Override
public ItemStack transferStackInSlot(EntityPlayer player, int index)
{
Slot slot = getSlot(index);
if((slot==null) || (!slot.getHasStack())) return ItemStack.EMPTY;
ItemStack slot_stack = slot.getStack();
ItemStack transferred = slot_stack.copy();
if((index>=0) && (index<PLAYER_INV_START_SLOTNO)) {
// Crate slots
if(!mergeItemStack(slot_stack, PLAYER_INV_START_SLOTNO, PLAYER_INV_START_SLOTNO+36, false)) return ItemStack.EMPTY;
} else if((index >= PLAYER_INV_START_SLOTNO) && (index <= PLAYER_INV_START_SLOTNO+36)) {
// Player slot
if(!mergeItemStack(slot_stack, 0, PLAYER_INV_START_SLOTNO-1, false)) return ItemStack.EMPTY;
} else {
// invalid slot
return ItemStack.EMPTY;
}
if(slot_stack.isEmpty()) {
slot.putStack(ItemStack.EMPTY);
} else {
slot.onSlotChanged();
}
if(slot_stack.getCount() == transferred.getCount()) return ItemStack.EMPTY;
slot.onTake(player, slot_stack);
return transferred;
}
}
//--------------------------------------------------------------------------------------------------------------------
// ModEngineersDecor.GuiHandler connectors
//--------------------------------------------------------------------------------------------------------------------
public static Object getServerGuiElement(final EntityPlayer player, final World world, final BlockPos pos, final TileEntity te)
{ return (te instanceof LabeledCrateTileEntity) ? (new BContainer(player.inventory, world, pos, (LabeledCrateTileEntity)te)) : null; }
public static Object getClientGuiElement(final EntityPlayer player, final World world, final BlockPos pos, final TileEntity te)
{ return (te instanceof LabeledCrateTileEntity) ? (new BGui(player.inventory, world, pos, (LabeledCrateTileEntity)te)) : null; }
}

View file

@ -27,6 +27,8 @@ import net.minecraft.item.ItemStack;
import net.minecraft.util.math.MathHelper;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import wile.engineersdecor.blocks.BlockDecorLabeledCrate;
import wile.engineersdecor.blocks.BlockDecorLabeledCrate.DecorLabeledCrateBlock;
import wile.engineersdecor.blocks.BlockDecorTest;
public class ModTesrs
@ -82,13 +84,58 @@ public class ModTesrs
}
} catch(Throwable e) {
if(--tesr_error_counter<=0) {
ModEngineersDecor.logger.error("TESR was disabled because broken, exception was: " + e.getMessage());
ModEngineersDecor.logger.error("Crafting Table TESR was disabled because broken, exception was: " + e.getMessage());
ModEngineersDecor.logger.error(e.getStackTrace());
}
}
}
}
//--------------------------------------------------------------------------------------------------------------------
// Labeled Crate
//--------------------------------------------------------------------------------------------------------------------
@SideOnly(Side.CLIENT)
public static class TesrDecorLabeledCrate extends TileEntitySpecialRenderer<BlockDecorLabeledCrate.LabeledCrateTileEntity>
{
private static int tesr_error_counter = 4;
private static double scaler = 0.35;
double tr[][]= { // [hdirection=S-W-N-E][param]
{ +8.0/32, -8.0/32, +15.5/32, 180.0 }, // N
{ -15.5/32, -8.0/32, +8.0/32, 90.0 }, // E
{ -8.0/32, -8.0/32, -15.5/32, 0.0 }, // S param=tx,ty,tz,ry
{ +15.5/32, -8.0/32, -8.0/32, 270.0 }, // W
};
@Override
public void render(final BlockDecorLabeledCrate.LabeledCrateTileEntity te, final double x, final double y, final double z, final float partialTicks, final int destroyStage, final float alpha)
{
if(tesr_error_counter<=0) return;
try {
final ItemStack stack = te.getItemFrameStack();
if(stack.isEmpty()) return;
final int di = MathHelper.clamp(te.getWorld().getBlockState(te.getPos()).getValue(DecorLabeledCrateBlock.FACING).getHorizontalIndex(), 0, 3);
double ox = tr[di][0], oy = tr[di][1], oz = tr[di][2], ry = tr[di][3];
GlStateManager.pushMatrix();
GlStateManager.disableLighting();
RenderHelper.enableStandardItemLighting();
GlStateManager.translate(x+0.5+ox, y+0.5+oy, z+0.5+oz);
GlStateManager.rotate((float)ry, 0, 1, 0);
GlStateManager.scale(scaler, scaler, scaler);
Minecraft.getMinecraft().getRenderItem().renderItem(stack, TransformType.FIXED);
RenderHelper.disableStandardItemLighting();
GlStateManager.enableLighting();
GlStateManager.popMatrix();
} catch(Throwable e) {
if(--tesr_error_counter<=0) {
ModEngineersDecor.logger.error("Labeled Crate TESR was disabled (because broken), exception was: " + e.getMessage());
}
}
}
}
//--------------------------------------------------------------------------------------------------------------------
// Test Block
//--------------------------------------------------------------------------------------------------------------------
@SideOnly(Side.CLIENT)

View file

@ -0,0 +1,11 @@
{
"forge_marker": 1,
"defaults": {
"model": "engineersdecor:misc/labeled_crate_model"
},
"variants": {
"normal": [{}],
"inventory": [{}],
"facing": { "north": {"y":0}, "south": {"y":180}, "west": {"y":-90}, "east": {"y":90}, "up":{}, "down":{} }
}
}

View file

@ -108,6 +108,8 @@ tile.engineersdecor.treated_wood_crafting_table.help=§6Robust and weather-proof
to clear crafting grid and history. Shift-click stack: player-to-storage stack transfer when crafting \
grid empty, otherwise player-to-grid stack transfer. Automatically distributes the clicked stack. \
Shift-Ctrl-click stack: Move all same stacks. Mouse wheel over crafting slot: Increase/decrease crafting grid items.
tile.engineersdecor.labeled_crate.name=Labeled Crate
tile.engineersdecor.labeled_crate.help=§6§6A storage crate with 9x6 slots and a built-in item frame at the front.§r\nPlace an item into the frame slot at the bottom right of the GUI to define the shown label.
tile.engineersdecor.treated_wood_side_table.name=Treated Wood Side Table
tile.engineersdecor.treated_wood_side_table.help=§6Needed after the work's done.
tile.engineersdecor.iron_inset_light.name=Inset Light

View file

@ -108,6 +108,8 @@ tile.engineersdecor.treated_wood_crafting_table.help=§6Прочный и уст
  очистить сетку крафта и историю. Shift-клик по стеку: передача стека от игрока в хранилище при создании \
если сетка пуста, в противном случае перенос от игрока в сетку. Автоматически распределяет кликаемый стек. \
Shift-Ctrl-клик по стаку: перемещает одинаковые стаки. Колёсико мыши: добавляет/отнимает предметы в сетке.
tile.engineersdecor.labeled_crate.name=Labeled Crate
tile.engineersdecor.labeled_crate.help=§6§6A storage crate with 9x6 slots and a built-in item frame at the front.§r\nPlace an item into the frame slot at the bottom right of the GUI to define the shown label.
tile.engineersdecor.treated_wood_side_table.name=Столик из обработанного дерева
tile.engineersdecor.treated_wood_side_table.help=§6Нужен после того, как работа выполнена.
tile.engineersdecor.iron_inset_light.name=Встраиваемый осветитель

View file

@ -107,6 +107,8 @@ tile.engineersdecor.treated_wood_crafting_table.help=§6坚固防风防雨。
单击上/下箭头按钮可选择合成历史单击输出格自动放置物品单击X按钮\
清除合成栏和历史。Shift单击一叠物品合成格空时转移到存储格\
非空时到合成栏。会自动分配转移的物品。
tile.engineersdecor.labeled_crate.name=Labeled Crate
tile.engineersdecor.labeled_crate.help=§6§6A storage crate with 9x6 slots and a built-in item frame at the front.§r\nPlace an item into the frame slot at the bottom right of the GUI to define the shown label.
tile.engineersdecor.treated_wood_side_table.name=防腐木茶几
tile.engineersdecor.treated_wood_side_table.help=§6干完活后需要喝杯茶。
tile.engineersdecor.iron_inset_light.name=嵌入灯

View file

@ -0,0 +1,77 @@
{
"parent": "block/block",
"textures": {
"f": "engineersdecor:blocks/misc/labeled_crate_front_texture",
"particle": "engineersdecor:blocks/misc/labeled_crate_side_texture",
"s": "engineersdecor:blocks/misc/labeled_crate_side_texture"
},
"elements": [
{
"from": [0, 7, 0],
"to": [16, 16, 0.25],
"faces": {
"north": {"texture": "#f"},
"east": {"texture": "#s"},
"west": {"texture": "#s"},
"up": {"texture": "#s"},
"down": {"texture": "#s"}
}
},
{
"from": [0, 0, 0.25],
"to": [16, 16, 16],
"faces": {
"north": {"texture": "#f"},
"east": {"texture": "#s"},
"south": {"texture": "#s"},
"west": {"texture": "#s"},
"up": {"texture": "#s"},
"down": {"texture": "#s"}
}
},
{
"from": [7, 0, 0],
"to": [16, 7, 0.25],
"faces": {
"north": {"texture": "#f"},
"east": {"texture": "#s"},
"south": {"texture": "#s"},
"west": {"texture": "#s"},
"down": {"texture": "#s"}
}
},
{
"from": [0, 0, 0],
"to": [1, 7, 0.375],
"faces": {
"north": {"texture": "#f"},
"east": {"texture": "#s"},
"south": {"texture": "#s"},
"west": {"texture": "#s"},
"down": {"texture": "#s"}
}
},
{
"from": [1, 0, 0],
"to": [7, 1, 0.25],
"faces": {
"north": {"texture": "#f"},
"up": {"texture": "#s"},
"down": {"texture": "#s"}
}
}
],
"display": {
"ground": {
"translation": [0, 1.75, 0],
"scale": [0.2, 0.2, 0.2]
},
"gui": {
"rotation": [30, 225, 0],
"scale": [0.625, 0.625, 0.625]
},
"fixed": {
"scale": [0.5, 0.5, 0.5]
}
}
}

View file

@ -0,0 +1,33 @@
{
"conditions": [
{
"type": "engineersdecor:grc",
"result": "engineersdecor:labeled_crate",
"missing": ["immersiveengineering:material"]
}
],
"type": "minecraft:crafting_shaped",
"pattern": [
"RCR",
"CFC",
"RCR"
],
"key": {
"R": {
"item": "minecraft:iron_nugget",
"data": 0
},
"C": {
"item": "minecraft:chest",
"data": 0
},
"F": {
"item": "minecraft:item_frame",
"data": 0
}
},
"result": {
"item": "engineersdecor:labeled_crate",
"count": 1
}
}

View file

@ -0,0 +1,33 @@
{
"conditions": [
{
"type": "engineersdecor:grc",
"result": "engineersdecor:labeled_crate",
"required": ["immersiveengineering:material"]
}
],
"type": "minecraft:crafting_shaped",
"pattern": [
"RCR",
"CFC",
"RCR"
],
"key": {
"R": {
"item": "#stickIron",
"data": 0
},
"C": {
"item": "#crateTreatedWood",
"data": 0
},
"F": {
"item": "minecraft:item_frame",
"data": 0
}
},
"result": {
"item": "engineersdecor:labeled_crate",
"count": 1
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 662 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 672 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 22 KiB

After

Width:  |  Height:  |  Size: 25 KiB

Before After
Before After