Added item distributor

This commit is contained in:
Ellpeck 2016-09-09 21:43:33 +02:00
parent 37d1bc95f9
commit e580fd2219
14 changed files with 195 additions and 10 deletions

View file

@ -0,0 +1,71 @@
/*
* This file ("BlockDistributor.java") is part of the Actually Additions mod for Minecraft.
* It is created and owned by Ellpeck and distributed
* under the Actually Additions License to be found at
* http://ellpeck.de/actaddlicense
* View the source code at https://github.com/Ellpeck/ActuallyAdditions
*
* © 2015-2016 Ellpeck
*/
package de.ellpeck.actuallyadditions.mod.blocks;
import de.ellpeck.actuallyadditions.mod.blocks.base.BlockContainerBase;
import de.ellpeck.actuallyadditions.mod.tile.TileEntityDistributorItem;
import de.ellpeck.actuallyadditions.mod.util.AssetUtil;
import de.ellpeck.actuallyadditions.mod.util.ModUtil;
import de.ellpeck.actuallyadditions.mod.util.StringUtil;
import net.minecraft.block.SoundType;
import net.minecraft.block.material.Material;
import net.minecraft.block.state.IBlockState;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.ScaledResolution;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.RayTraceResult;
import net.minecraft.util.text.TextFormatting;
import net.minecraft.world.World;
public class BlockDistributorItem extends BlockContainerBase implements IHudDisplay{
public BlockDistributorItem(String name){
super(Material.ROCK, name);
this.setHarvestLevel("pickaxe", 0);
this.setHardness(1.75F);
this.setResistance(10.0F);
this.setSoundType(SoundType.STONE);
}
@Override
public TileEntity createNewTileEntity(World worldIn, int meta){
return new TileEntityDistributorItem();
}
@Override
public void breakBlock(World world, BlockPos pos, IBlockState state){
this.dropInventory(world, pos);
super.breakBlock(world, pos, state);
}
@Override
public void displayHud(Minecraft minecraft, EntityPlayer player, ItemStack stack, RayTraceResult posHit, ScaledResolution resolution){
TileEntity tile = minecraft.theWorld.getTileEntity(posHit.getBlockPos());
if(tile instanceof TileEntityDistributorItem){
TileEntityDistributorItem distributor = (TileEntityDistributorItem)tile;
ItemStack slot = distributor.getStackInSlot(0);
String strg;
if(slot == null){
strg = StringUtil.localize("info."+ModUtil.MOD_ID+".noItem");
}
else{
strg = slot.getItem().getItemStackDisplayName(slot);
AssetUtil.renderStackToGui(slot, resolution.getScaledWidth()/2+15, resolution.getScaledHeight()/2-19, 1F);
}
minecraft.fontRendererObj.drawStringWithShadow(TextFormatting.YELLOW+""+TextFormatting.ITALIC+strg, resolution.getScaledWidth()/2+35, resolution.getScaledHeight()/2-15, StringUtil.DECIMAL_COLOR_WHITE);
}
}
}

View file

@ -68,7 +68,6 @@ public class BlockTinyTorch extends BlockBase{
} }
@Override @Override
@Nullable
public AxisAlignedBB getCollisionBoundingBox(IBlockState blockState, World worldIn, BlockPos pos){ public AxisAlignedBB getCollisionBoundingBox(IBlockState blockState, World worldIn, BlockPos pos){
return NULL_AABB; return NULL_AABB;
} }

View file

@ -126,12 +126,14 @@ public final class InitBlocks{
public static Block blockDisplayStand; public static Block blockDisplayStand;
public static Block blockShockSuppressor; public static Block blockShockSuppressor;
public static Block blockEmpowerer; public static Block blockEmpowerer;
public static Block blockDistributorItem;
public static Block blockTinyTorch; public static Block blockTinyTorch;
public static void init(){ public static void init(){
ModUtil.LOGGER.info("Initializing Blocks..."); ModUtil.LOGGER.info("Initializing Blocks...");
blockDistributorItem = new BlockDistributorItem("blockDistributorItem");
blockEmpowerer = new BlockEmpowerer("blockEmpowerer"); blockEmpowerer = new BlockEmpowerer("blockEmpowerer");
blockTinyTorch = new BlockTinyTorch("blockTinyTorch"); blockTinyTorch = new BlockTinyTorch("blockTinyTorch");
blockShockSuppressor = new BlockShockSuppressor("blockShockSuppressor"); blockShockSuppressor = new BlockShockSuppressor("blockShockSuppressor");

View file

@ -87,6 +87,7 @@ public class CreativeTab extends CreativeTabs{
this.add(InitBlocks.blockCoffeeMachine); this.add(InitBlocks.blockCoffeeMachine);
this.add(InitBlocks.blockXPSolidifier); this.add(InitBlocks.blockXPSolidifier);
this.add(InitBlocks.blockDisplayStand); this.add(InitBlocks.blockDisplayStand);
this.add(InitBlocks.blockDistributorItem);
this.add(InitBlocks.blockShockSuppressor); this.add(InitBlocks.blockShockSuppressor);
this.add(InitBlocks.blockMiner); this.add(InitBlocks.blockMiner);

View file

@ -51,7 +51,7 @@ public class ContainerBag extends Container implements IButtonReactor{
if(this.isVoid){ if(this.isVoid){
this.addSlotToContainer(new SlotDeletion(this.bagInventory, 4, 64, 65){ this.addSlotToContainer(new SlotDeletion(this.bagInventory, 4, 64, 65){
@Override @Override
public boolean isItemValid(@Nullable ItemStack stack){ public boolean isItemValid(ItemStack stack){
return ContainerBag.this.filter.check(stack, ContainerBag.this.bagInventory.slots); return ContainerBag.this.filter.check(stack, ContainerBag.this.bagInventory.slots);
} }
}); });
@ -61,7 +61,7 @@ public class ContainerBag extends Container implements IButtonReactor{
for(int j = 0; j < 7; j++){ for(int j = 0; j < 7; j++){
this.addSlotToContainer(new Slot(this.bagInventory, j+i*7+4, 10+j*18, 10+i*18){ this.addSlotToContainer(new Slot(this.bagInventory, j+i*7+4, 10+j*18, 10+i*18){
@Override @Override
public boolean isItemValid(@Nullable ItemStack stack){ public boolean isItemValid(ItemStack stack){
return ContainerBag.this.filter.check(stack, ContainerBag.this.bagInventory.slots); return ContainerBag.this.filter.check(stack, ContainerBag.this.bagInventory.slots);
} }
}); });

View file

@ -79,7 +79,6 @@ public class BookletRecipeWrapper extends RecipeWrapperWithButton implements IRe
} }
@Nullable
@Override @Override
public List<String> getTooltipStrings(int mouseX, int mouseY){ public List<String> getTooltipStrings(int mouseX, int mouseY){
return null; return null;

View file

@ -87,7 +87,6 @@ public class CoffeeMachineRecipeWrapper extends RecipeWrapperWithButton implemen
} }
@Nullable
@Override @Override
public List<String> getTooltipStrings(int mouseX, int mouseY){ public List<String> getTooltipStrings(int mouseX, int mouseY){
return null; return null;

View file

@ -77,7 +77,6 @@ public class CrusherRecipeWrapper extends RecipeWrapperWithButton implements IRe
} }
@Nullable
@Override @Override
public List<String> getTooltipStrings(int mouseX, int mouseY){ public List<String> getTooltipStrings(int mouseX, int mouseY){
return null; return null;

View file

@ -66,7 +66,6 @@ public class EmpowererRecipeWrapper extends RecipeWrapperWithButton implements I
} }
@Nullable
@Override @Override
public List<String> getTooltipStrings(int mouseX, int mouseY){ public List<String> getTooltipStrings(int mouseX, int mouseY){
return null; return null;

View file

@ -63,7 +63,6 @@ public class ReconstructorRecipeWrapper extends RecipeWrapperWithButton implemen
} }
@Nullable
@Override @Override
public List<String> getTooltipStrings(int mouseX, int mouseY){ public List<String> getTooltipStrings(int mouseX, int mouseY){
return null; return null;

View file

@ -108,6 +108,7 @@ public abstract class TileEntityBase extends TileEntity implements ITickable{
register(TileEntityShockSuppressor.class, "ShockSuppressor"); register(TileEntityShockSuppressor.class, "ShockSuppressor");
register(TileEntityEmpowerer.class); register(TileEntityEmpowerer.class);
register(TileEntityLaserRelayFluids.class); register(TileEntityLaserRelayFluids.class);
register(TileEntityDistributorItem.class);
} }
private static void register(Class<? extends TileEntityBase> tileClass, String legacyName){ private static void register(Class<? extends TileEntityBase> tileClass, String legacyName){

View file

@ -0,0 +1,115 @@
/*
* This file ("TileEntityDistributorItem.java") is part of the Actually Additions mod for Minecraft.
* It is created and owned by Ellpeck and distributed
* under the Actually Additions License to be found at
* http://ellpeck.de/actaddlicense
* View the source code at https://github.com/Ellpeck/ActuallyAdditions
*
* © 2015-2016 Ellpeck
*/
package de.ellpeck.actuallyadditions.mod.tile;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumFacing;
import net.minecraftforge.items.CapabilityItemHandler;
import net.minecraftforge.items.IItemHandler;
public class TileEntityDistributorItem extends TileEntityInventoryBase{
private int sidePutTo;
private int lastSlotAmount;
public TileEntityDistributorItem(){
super(1, "distributorItem");
}
@Override
public void updateEntity(){
super.updateEntity();
if(!this.worldObj.isRemote){
if(this.slots[0] != null){
TileEntity tile = this.tilesAround[this.sidePutTo];
if(tile != null){
EnumFacing side = EnumFacing.values()[this.sidePutTo].getOpposite();
if(tile.hasCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, side)){
IItemHandler cap = tile.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, side);
if(cap != null){
int amountPer = this.slots[0].stackSize/5;
if(amountPer <= 0){
amountPer = this.slots[0].stackSize;
}
ItemStack stackToPut = this.slots[0].copy();
stackToPut.stackSize = amountPer;
for(int i = 0; i < cap.getSlots(); i++){
stackToPut = cap.insertItem(i, stackToPut.copy(), false);
if(stackToPut == null){
this.slots[0].stackSize -= amountPer;
break;
}
else{
this.slots[0].stackSize -= stackToPut.stackSize;
}
}
}
}
}
this.sidePutTo++;
if(this.sidePutTo == 1){
this.sidePutTo++;
}
else if(this.sidePutTo >= 6){
this.sidePutTo = 0;
}
}
int stackSize = this.slots[0] == null ? 0 : this.slots[0].stackSize;
if(stackSize != this.lastSlotAmount && this.sendUpdateWithInterval()){
this.lastSlotAmount = stackSize;
}
}
}
@Override
public void writeSyncableNBT(NBTTagCompound compound, NBTType type){
super.writeSyncableNBT(compound, type);
compound.setInteger("PutSide", this.sidePutTo);
}
@Override
public void readSyncableNBT(NBTTagCompound compound, NBTType type){
super.readSyncableNBT(compound, type);
this.sidePutTo = compound.getInteger("PutSide");
}
@Override
public boolean shouldSyncSlots(){
return true;
}
@Override
public boolean shouldSaveHandlersAround(){
return true;
}
@Override
public boolean canInsertItem(int index, ItemStack stack, EnumFacing direction){
return direction == EnumFacing.UP && this.isItemValidForSlot(index, stack);
}
@Override
public boolean canExtractItem(int index, ItemStack stack, EnumFacing direction){
return true;
}
@Override
public boolean isItemValidForSlot(int index, ItemStack stack){
return true;
}
}

View file

@ -52,12 +52,12 @@ public class ItemTeslaWrapper implements ITeslaProducer, ITeslaHolder, ITeslaCon
} }
@Override @Override
public boolean hasCapability(Capability<?> capability, @Nullable EnumFacing facing){ public boolean hasCapability(Capability<?> capability, EnumFacing facing){
return capability == TeslaUtil.teslaProducer || capability == TeslaUtil.teslaHolder || capability == TeslaUtil.teslaConsumer; return capability == TeslaUtil.teslaProducer || capability == TeslaUtil.teslaHolder || capability == TeslaUtil.teslaConsumer;
} }
@Override @Override
public <T> T getCapability(Capability<T> capability, @Nullable EnumFacing facing){ public <T> T getCapability(Capability<T> capability, EnumFacing facing){
return this.hasCapability(capability, facing) ? (T)this : null; return this.hasCapability(capability, facing) ? (T)this : null;
} }
} }

View file

@ -570,6 +570,7 @@ info.actuallyadditions.gui.smartInfo=When pressing this, all items from inventor
info.actuallyadditions.inputter.info.1=This is the first Slot in the connected Inventory to <p> at. info.actuallyadditions.inputter.info.1=This is the first Slot in the connected Inventory to <p> at.
info.actuallyadditions.inputter.info.2=This is the slot after the last Slot in the connected Inventory to <p> at. What that means: If you, for example, write 2 in the field to the left and 5 in this one, it will <p> at Slot 2, 3, and 4. info.actuallyadditions.inputter.info.2=This is the slot after the last Slot in the connected Inventory to <p> at. What that means: If you, for example, write 2 in the field to the left and 5 in this one, it will <p> at Slot 2, 3, and 4.
info.actuallyadditions.noLens=No Lens info.actuallyadditions.noLens=No Lens
info.actuallyadditions.noItem=No Items in Buffer
info.actuallyadditions.booklet.manualName.1.1=Actually Additions info.actuallyadditions.booklet.manualName.1.1=Actually Additions
info.actuallyadditions.booklet.manualName.1.2=Actual Additions info.actuallyadditions.booklet.manualName.1.2=Actual Additions
info.actuallyadditions.booklet.manualName.1.3=Actually Addiction info.actuallyadditions.booklet.manualName.1.3=Actually Addiction