start of infusion

This commit is contained in:
Ellpeck 2018-10-18 13:34:37 +02:00
parent 43fb4daddc
commit f8ff74b36b
19 changed files with 293 additions and 54 deletions

View file

@ -1,16 +1,20 @@
package de.ellpeck.naturesaura;
import de.ellpeck.naturesaura.blocks.tiles.TileEntityImpl;
import net.minecraft.block.state.IBlockState;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.client.renderer.RenderHelper;
import net.minecraft.client.renderer.block.model.ItemCameraTransforms;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumHand;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import net.minecraftforge.items.IItemHandlerModifiable;
import java.util.ArrayList;
import java.util.List;
@ -73,4 +77,32 @@ public final class Helper {
GlStateManager.popMatrix();
}
}
public static boolean putStackOnTile(EntityPlayer player, EnumHand hand, BlockPos pos, int slot) {
TileEntity tile = player.world.getTileEntity(pos);
if (tile instanceof TileEntityImpl) {
IItemHandlerModifiable handler = ((TileEntityImpl) tile).getItemHandler(null);
if (handler != null) {
ItemStack handStack = player.getHeldItem(hand);
if (!handStack.isEmpty()) {
ItemStack remain = handler.insertItem(slot, handStack, player.world.isRemote);
if (!ItemStack.areItemStacksEqual(remain, handStack)) {
if (!player.world.isRemote) {
player.setHeldItem(hand, remain);
}
return true;
}
}
if (!handler.getStackInSlot(slot).isEmpty()) {
if (!player.world.isRemote) {
player.addItemStackToInventory(handler.getStackInSlot(slot));
handler.setStackInSlot(slot, ItemStack.EMPTY);
}
return true;
}
}
}
return false;
}
}

View file

@ -1,21 +1,25 @@
package de.ellpeck.naturesaura.blocks;
import de.ellpeck.naturesaura.NaturesAura;
import de.ellpeck.naturesaura.blocks.tiles.TileEntityImpl;
import de.ellpeck.naturesaura.reg.IModItem;
import de.ellpeck.naturesaura.reg.IModelProvider;
import de.ellpeck.naturesaura.reg.ModRegistry;
import net.minecraft.block.BlockContainer;
import net.minecraft.block.material.Material;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumBlockRenderType;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPostInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
import net.minecraftforge.fml.common.registry.GameRegistry;
import net.minecraftforge.items.IItemHandler;
import javax.annotation.Nullable;
import java.util.Collections;
@ -81,4 +85,24 @@ public class BlockContainerImpl extends BlockContainer implements IModItem, IMod
public EnumBlockRenderType getRenderType(IBlockState state) {
return EnumBlockRenderType.MODEL;
}
@Override
public void breakBlock(World worldIn, BlockPos pos, IBlockState state) {
if (!worldIn.isRemote) {
TileEntity tile = worldIn.getTileEntity(pos);
if (tile instanceof TileEntityImpl) {
IItemHandler handler = ((TileEntityImpl) tile).getItemHandler(null);
if (handler != null) {
for (int i = 0; i < handler.getSlots(); i++) {
ItemStack stack = handler.getStackInSlot(i);
if (!stack.isEmpty()) {
EntityItem item = new EntityItem(worldIn, pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5, stack);
worldIn.spawnEntity(item);
}
}
}
}
}
super.breakBlock(worldIn, pos, state);
}
}

View file

@ -1,11 +1,16 @@
package de.ellpeck.naturesaura.blocks;
import de.ellpeck.naturesaura.Helper;
import de.ellpeck.naturesaura.blocks.tiles.TileEntityNatureAltar;
import net.minecraft.block.material.Material;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.player.EntityPlayer;
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.world.IBlockAccess;
import net.minecraft.world.World;
public class BlockNatureAltar extends BlockContainerImpl {
@ -17,6 +22,11 @@ public class BlockNatureAltar extends BlockContainerImpl {
this.setHarvestLevel("pickaxe", 1);
}
@Override
public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
return Helper.putStackOnTile(playerIn, hand, pos, 0);
}
@Override
public AxisAlignedBB getBoundingBox(IBlockState state, IBlockAccess source, BlockPos pos) {
return BOUND_BOX;

View file

@ -1,12 +1,12 @@
package de.ellpeck.naturesaura.blocks;
import de.ellpeck.naturesaura.Helper;
import de.ellpeck.naturesaura.blocks.tiles.TileEntityWoodStand;
import net.minecraft.block.SoundType;
import net.minecraft.block.material.Material;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumHand;
@ -28,46 +28,7 @@ public class BlockWoodStand extends BlockContainerImpl {
@Override
public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
TileEntity tile = worldIn.getTileEntity(pos);
if (tile instanceof TileEntityWoodStand) {
TileEntityWoodStand stand = (TileEntityWoodStand) tile;
if (stand.stack.isEmpty()) {
ItemStack handStack = playerIn.getHeldItem(hand);
if (!handStack.isEmpty()) {
if (!worldIn.isRemote) {
ItemStack copy = handStack.copy();
copy.setCount(1);
stand.stack = copy;
handStack.shrink(1);
stand.sendToClients();
}
return true;
}
} else {
if (!worldIn.isRemote) {
playerIn.addItemStackToInventory(stand.stack);
stand.stack = ItemStack.EMPTY;
stand.sendToClients();
}
return true;
}
}
return false;
}
@Override
public void breakBlock(World worldIn, BlockPos pos, IBlockState state) {
if (!worldIn.isRemote) {
TileEntity tile = worldIn.getTileEntity(pos);
if (tile instanceof TileEntityWoodStand) {
TileEntityWoodStand stand = (TileEntityWoodStand) tile;
if (!stand.stack.isEmpty()) {
EntityItem item = new EntityItem(worldIn, pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5, stand.stack);
worldIn.spawnEntity(item);
}
}
}
super.breakBlock(worldIn, pos, state);
return Helper.putStackOnTile(playerIn, hand, pos, 0);
}
@Override

View file

@ -0,0 +1,62 @@
package de.ellpeck.naturesaura.blocks.tiles;
import net.minecraft.item.ItemStack;
import net.minecraftforge.items.ItemStackHandler;
import javax.annotation.Nonnull;
public class ItemStackHandlerNA extends ItemStackHandler {
private final TileEntityImpl tile;
private final boolean sendToClients;
public ItemStackHandlerNA(int size) {
this(size, null, false);
}
public ItemStackHandlerNA(int size, TileEntityImpl tile, boolean sendToClients) {
super(size);
this.tile = tile;
this.sendToClients = sendToClients;
}
@Override
protected void onContentsChanged(int slot) {
if (this.sendToClients && !this.tile.getWorld().isRemote) {
this.tile.sendToClients();
}
}
protected boolean canInsert(ItemStack stack, int slot) {
return true;
}
protected boolean canExtract(ItemStack stack, int slot, int amount) {
return true;
}
@Override
public boolean isItemValid(int slot, @Nonnull ItemStack stack) {
return this.canInsert(stack, slot);
}
@Nonnull
@Override
public ItemStack insertItem(int slot, @Nonnull ItemStack stack, boolean simulate) {
if (this.canInsert(stack, slot)) {
return super.insertItem(slot, stack, simulate);
} else {
return stack;
}
}
@Nonnull
@Override
public ItemStack extractItem(int slot, int amount, boolean simulate) {
if (this.canExtract(this.getStackInSlot(slot), slot, amount)) {
return super.extractItem(slot, amount, simulate);
} else {
return ItemStack.EMPTY;
}
}
}

View file

@ -1,15 +1,21 @@
package de.ellpeck.naturesaura.blocks.tiles;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.network.NetworkManager;
import net.minecraft.network.play.server.SPacketUpdateTileEntity;
import net.minecraft.server.management.PlayerChunkMapEntry;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraft.world.WorldServer;
import net.minecraftforge.common.capabilities.Capability;
import net.minecraftforge.items.CapabilityItemHandler;
import net.minecraftforge.items.IItemHandler;
import net.minecraftforge.items.IItemHandlerModifiable;
import javax.annotation.Nullable;
public class TileEntityImpl extends TileEntity {
@Override
@ -68,4 +74,27 @@ public class TileEntityImpl extends TileEntity {
entry.sendPacket(this.getUpdatePacket());
}
}
public IItemHandlerModifiable getItemHandler(EnumFacing facing) {
return null;
}
@Override
public boolean hasCapability(Capability<?> capability, @Nullable EnumFacing facing) {
if (capability == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY) {
return this.getItemHandler(facing) != null;
} else {
return super.hasCapability(capability, facing);
}
}
@Nullable
@Override
public <T> T getCapability(Capability<T> capability, @Nullable EnumFacing facing) {
if (capability == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY) {
return (T) this.getItemHandler(facing);
} else {
return super.getCapability(capability, facing);
}
}
}

View file

@ -7,14 +7,19 @@ import de.ellpeck.naturesaura.aura.IAuraContainer;
import de.ellpeck.naturesaura.aura.IAuraContainerProvider;
import de.ellpeck.naturesaura.packet.PacketHandler;
import de.ellpeck.naturesaura.packet.PacketParticleStream;
import de.ellpeck.naturesaura.recipes.AltarRecipe;
import net.minecraft.block.BlockStoneBrick;
import net.minecraft.block.BlockStoneBrick.EnumType;
import net.minecraft.block.state.IBlockState;
import net.minecraft.init.Blocks;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.ITickable;
import net.minecraft.util.math.BlockPos;
import net.minecraftforge.items.IItemHandlerModifiable;
import net.minecraftforge.items.ItemStackHandler;
import java.util.ArrayList;
import java.util.List;
@ -55,7 +60,6 @@ public class TileEntityNatureAltar extends TileEntityImpl implements ITickable,
new BlockPos(-2, 0, 2)
};
private static final BlockPos[] CHISELED_POSITIONS = new BlockPos[]{
new BlockPos(0, -1, 0),
new BlockPos(1, -1, 1),
new BlockPos(-1, -1, 1),
new BlockPos(-1, -1, -1),
@ -88,6 +92,23 @@ public class TileEntityNatureAltar extends TileEntityImpl implements ITickable,
new BlockPos(1, -1, 3),
};
public final ItemStackHandler items = new ItemStackHandlerNA(1, this, true) {
@Override
public int getSlotLimit(int slot) {
return 1;
}
@Override
protected boolean canInsert(ItemStack stack, int slot) {
return AltarRecipe.forInput(stack) != null;
}
@Override
protected boolean canExtract(ItemStack stack, int slot, int amount) {
return AltarRecipe.forInput(stack) == null;
}
};
private final List<IAuraContainerProvider> cachedProviders = new ArrayList<>();
private final BasicAuraContainer container = new BasicAuraContainer(5000);
public boolean structureFine;
@ -182,6 +203,7 @@ public class TileEntityNatureAltar extends TileEntityImpl implements ITickable,
@Override
public void writeNBT(NBTTagCompound compound, boolean syncing) {
super.writeNBT(compound, syncing);
compound.setTag("items", this.items.serializeNBT());
compound.setBoolean("fine", this.structureFine);
this.container.writeNBT(compound);
}
@ -189,6 +211,7 @@ public class TileEntityNatureAltar extends TileEntityImpl implements ITickable,
@Override
public void readNBT(NBTTagCompound compound, boolean syncing) {
super.readNBT(compound, syncing);
this.items.deserializeNBT(compound.getCompoundTag("items"));
this.structureFine = compound.getBoolean("fine");
this.container.readNBT(compound);
}
@ -202,4 +225,9 @@ public class TileEntityNatureAltar extends TileEntityImpl implements ITickable,
public boolean isArtificial() {
return true;
}
@Override
public IItemHandlerModifiable getItemHandler(EnumFacing facing) {
return this.items;
}
}

View file

@ -17,6 +17,8 @@ import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.ITickable;
import net.minecraft.util.math.BlockPos;
import net.minecraftforge.items.IItemHandlerModifiable;
import net.minecraftforge.items.ItemStackHandler;
import java.util.HashMap;
import java.util.Map;
@ -41,7 +43,13 @@ public class TileEntityWoodStand extends TileEntityImpl implements ITickable {
new BlockPos(1, 0, -2),
new BlockPos(-1, 0, -2)
};
public ItemStack stack = ItemStack.EMPTY;
public final ItemStackHandler items = new ItemStackHandlerNA(1, this, true) {
@Override
public int getSlotLimit(int slot) {
return 1;
}
};
private BlockPos ritualPos;
private Map<BlockPos, ItemStack> involvedStands;
@ -102,7 +110,7 @@ public class TileEntityWoodStand extends TileEntityImpl implements ITickable {
for (BlockPos pos : this.involvedStands.keySet()) {
TileEntityWoodStand stand = (TileEntityWoodStand) this.world.getTileEntity(pos);
PacketHandler.sendToAllAround(this.world, this.pos, 32, new PacketParticles(stand.pos.getX(), stand.pos.getY(), stand.pos.getZ(), 1));
stand.stack = ItemStack.EMPTY;
stand.items.setStackInSlot(0, ItemStack.EMPTY);
stand.sendToClients();
}
}
@ -146,7 +154,8 @@ public class TileEntityWoodStand extends TileEntityImpl implements ITickable {
}
for (Map.Entry<BlockPos, ItemStack> entry : this.involvedStands.entrySet()) {
TileEntity tile = this.world.getTileEntity(entry.getKey());
if (!(tile instanceof TileEntityWoodStand) || (this.timer < this.totalTime / 2 && !((TileEntityWoodStand) tile).stack.isItemEqual(entry.getValue()))) {
if (!(tile instanceof TileEntityWoodStand)
|| (this.timer < this.totalTime / 2 && !((TileEntityWoodStand) tile).items.getStackInSlot(0).isItemEqual(entry.getValue()))) {
return false;
}
}
@ -156,7 +165,7 @@ public class TileEntityWoodStand extends TileEntityImpl implements ITickable {
@Override
public void writeNBT(NBTTagCompound compound, boolean syncing) {
super.writeNBT(compound, syncing);
compound.setTag("item", this.stack.writeToNBT(new NBTTagCompound()));
compound.setTag("items", this.items.serializeNBT());
if (!syncing) {
if (this.ritualPos != null && this.involvedStands != null && this.output != null && this.totalTime > 0) {
@ -180,7 +189,7 @@ public class TileEntityWoodStand extends TileEntityImpl implements ITickable {
@Override
public void readNBT(NBTTagCompound compound, boolean syncing) {
super.readNBT(compound, syncing);
this.stack = new ItemStack(compound.getCompoundTag("item"));
this.items.deserializeNBT(compound.getCompoundTag("items"));
if (!syncing) {
if (compound.hasKey("ritual_pos") && compound.hasKey("stands") && compound.hasKey("output") && compound.hasKey("total_time")) {
@ -201,4 +210,9 @@ public class TileEntityWoodStand extends TileEntityImpl implements ITickable {
}
}
}
@Override
public IItemHandlerModifiable getItemHandler(EnumFacing facing) {
return this.items;
}
}

View file

@ -0,0 +1,26 @@
package de.ellpeck.naturesaura.blocks.tiles.render;
import de.ellpeck.naturesaura.Helper;
import de.ellpeck.naturesaura.blocks.tiles.TileEntityNatureAltar;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
import net.minecraft.item.ItemBlock;
import net.minecraft.item.ItemStack;
public class RenderNatureAltar extends TileEntitySpecialRenderer<TileEntityNatureAltar> {
@Override
public void render(TileEntityNatureAltar tile, double x, double y, double z, float partialTicks, int destroyStage, float alpha) {
ItemStack stack = tile.items.getStackInSlot(0);
if (!stack.isEmpty()) {
GlStateManager.pushMatrix();
float time = tile.getWorld().getTotalWorldTime() + partialTicks;
float bob = (float) Math.sin(time / 10F) * 0.1F;
GlStateManager.translate(x + 0.5F, y + 1.2F + bob, z + 0.5F);
GlStateManager.rotate((time * 3) % 360, 0F, 1F, 0F);
float scale = stack.getItem() instanceof ItemBlock ? 0.75F : 0.5F;
GlStateManager.scale(scale, scale, scale);
Helper.renderItemInWorld(stack);
GlStateManager.popMatrix();
}
}
}

View file

@ -10,7 +10,7 @@ import net.minecraft.item.ItemStack;
public class RenderWoodStand extends TileEntitySpecialRenderer<TileEntityWoodStand> {
@Override
public void render(TileEntityWoodStand tile, double x, double y, double z, float partialTicks, int destroyStage, float alpha) {
ItemStack stack = tile.stack;
ItemStack stack = tile.items.getStackInSlot(0);
if (!stack.isEmpty()) {
GlStateManager.pushMatrix();
if (stack.getItem() instanceof ItemBlock) {

View file

@ -29,8 +29,9 @@ public class TerrainGenEvents {
for (TileEntity tile : tileEntities) {
if (tile instanceof TileEntityWoodStand) {
TileEntityWoodStand stand = (TileEntityWoodStand) tile;
if (!stand.stack.isEmpty()) {
usableItems.add(stand.stack);
ItemStack stack = stand.items.getStackInSlot(0);
if (!stack.isEmpty()) {
usableItems.add(stack);
stands.add(stand);
}
}
@ -46,9 +47,10 @@ public class TerrainGenEvents {
TileEntityWoodStand toPick = null;
for (TileEntityWoodStand stand : stands) {
int index = Helper.getItemIndex(stillRequired, stand.stack);
ItemStack stack = stand.items.getStackInSlot(0);
int index = Helper.getItemIndex(stillRequired, stack);
if (index >= 0) {
actuallyInvolved.put(stand.getPos(), stand.stack);
actuallyInvolved.put(stand.getPos(), stack);
stillRequired.remove(index);
if (toPick == null) {

View file

@ -7,4 +7,5 @@ public final class ModItems {
public static final Item EYE = new ItemEye();
public static final Item GOLD_FIBER = new ItemGoldFiber();
public static final Item GOLD_LEAF = new ItemImpl("gold_leaf");
public static final Item INFUSED_IRON = new ItemImpl("infused_iron");
}

View file

@ -1,6 +1,8 @@
package de.ellpeck.naturesaura.proxy;
import de.ellpeck.naturesaura.blocks.tiles.TileEntityNatureAltar;
import de.ellpeck.naturesaura.blocks.tiles.TileEntityWoodStand;
import de.ellpeck.naturesaura.blocks.tiles.render.RenderNatureAltar;
import de.ellpeck.naturesaura.blocks.tiles.render.RenderWoodStand;
import de.ellpeck.naturesaura.events.ClientEvents;
import de.ellpeck.naturesaura.particles.ParticleHandler;
@ -33,6 +35,7 @@ public class ClientProxy implements IProxy {
@Override
public void init(FMLInitializationEvent event) {
ClientRegistry.bindTileEntitySpecialRenderer(TileEntityWoodStand.class, new RenderWoodStand());
ClientRegistry.bindTileEntitySpecialRenderer(TileEntityNatureAltar.class, new RenderNatureAltar());
}
@Override

View file

@ -0,0 +1,37 @@
package de.ellpeck.naturesaura.recipes;
import net.minecraft.item.ItemStack;
import java.util.ArrayList;
import java.util.List;
public class AltarRecipe {
public static final List<AltarRecipe> RECIPES = new ArrayList<>();
public final ItemStack input;
public final ItemStack output;
public final int aura;
public final int time;
public AltarRecipe(ItemStack input, ItemStack output, int aura, int time) {
this.input = input;
this.output = output;
this.aura = aura;
this.time = time;
}
public static AltarRecipe forInput(ItemStack input) {
for (AltarRecipe recipe : RECIPES) {
if (recipe.input.isItemEqual(input)) {
return recipe;
}
}
return null;
}
public AltarRecipe add() {
RECIPES.add(this);
return this;
}
}

View file

@ -20,5 +20,7 @@ public final class ModRecipes {
new ItemStack(Blocks.STONE),
new ItemStack(ModItems.GOLD_LEAF),
new ItemStack(Items.DIAMOND)).add();
new AltarRecipe(new ItemStack(Items.IRON_INGOT), new ItemStack(ModItems.INFUSED_IRON), 100, 30).add();
}
}

View file

@ -35,7 +35,8 @@ public class TreeRitualRecipe {
}
}
public void add() {
public TreeRitualRecipe add() {
RECIPES.add(this);
return this;
}
}

View file

@ -13,5 +13,6 @@ tile.naturesaura.wood_stand.name=Wooden Stand
item.naturesaura.eye.name=Environmental Eye
item.naturesaura.gold_fiber.name=Brilliant Fiber
item.naturesaura.gold_leaf.name=Gold Leaf
item.naturesaura.infused_iron.name=Infused Iron
container.naturesaura.tree_ritual.name=Tree Infusion

View file

@ -0,0 +1,6 @@
{
"parent": "item/generated",
"textures": {
"layer0": "naturesaura:items/infused_iron"
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 634 B