Commit 505509f2 authored by mrAppleXZ's avatar mrAppleXZ 💾

Stone Crusher restoration, PXLMC update

parent 08ee097e
......@@ -102,7 +102,7 @@ public class ClientProxy extends CommonProxy
@Override
public void openMicroscope(TileMicroscope tile)
{
Minecraft.getMinecraft().displayGuiScreen(new PXLGui(new GuiMicroscope(tile.handler.getStackInSlot(0), tile.getPos())));
Minecraft.getMinecraft().displayGuiScreen(new PXLGui(new GuiMicroscope(tile.getHandler().getStackInSlot(0), tile.getPos())));
}
@Override
......@@ -122,4 +122,6 @@ public class ClientProxy extends CommonProxy
{
PurMag.INSTANCE.getIfRegistry().setupJei();
}
}
......@@ -96,7 +96,7 @@ public class GuiTranslationDesk extends GuiOnScreen
if (te != null && te instanceof TileTranslationDesk)
{
TileTranslationDesk ttd = (TileTranslationDesk) te;
ItemStack stack = ttd.handler.getStackInSlot(0);
ItemStack stack = ttd.getHandler().getStackInSlot(0);
if (panel.translating)
{
status = Status.TRANSLATING;
......
......@@ -25,7 +25,7 @@ public class TESRMicroscope extends PXLFastTESR<TileMicroscope>
IBlockState state = getWorld().getBlockState(te.getPos());
if (state.getBlock() != BlockRegistry.microscope)
return;
ItemStack stack = te.handler.getStackInSlot(0);
ItemStack stack = te.getHandler().getStackInSlot(0);
if (!stack.isEmpty())
{
......
......@@ -138,7 +138,7 @@ public abstract class BlockAbstractSingleItemHorizontal extends BlockBase
TileEntity te = worldIn.getTileEntity(pos);
if (te != null && te instanceof TileAbstractSingleItem)
{
ItemStackUtils.drop(((TileAbstractSingleItem) te).handler, worldIn, pos);
ItemStackUtils.drop(((TileAbstractSingleItem) te).getHandler(), worldIn, pos);
}
}
super.breakBlock(worldIn, pos, state);
......
......@@ -35,7 +35,7 @@ public class ContainerCodeStorage extends PXLContainer
{
for (int cx = 0; cx < 10; cx++)
{
addSlotToContainer(new SlotItemHandler(storage.handler, index, offx + cx * 18, offy + cy * 18));
addSlotToContainer(new SlotItemHandler(storage.getHandler(), index, offx + cx * 18, offy + cy * 18));
index++;
}
}
......
......@@ -62,7 +62,7 @@ public class SPacketDoneTranslation implements IMessage
if (te != null && te instanceof TileTranslationDesk)
{
TileTranslationDesk ttd = (TileTranslationDesk) te;
ItemStack papyrus = ttd.handler.getStackInSlot(0);
ItemStack papyrus = ttd.getHandler().getStackInSlot(0);
if (!papyrus.isEmpty())
{
IIfEntryStore store = p.getCapability(CapabilityRegistry.ENTRY_STORE_CAP, null);
......
......@@ -92,7 +92,7 @@ public class SPacketCheckMicroscopeResearch implements IMessage
TileEntity te = p.getEntityWorld().getTileEntity(message.pos);
if (te != null && te instanceof TileMicroscope)
{
if(pair.getRight().getIngredient().apply(((TileMicroscope) te).handler.getStackInSlot(0)))
if(pair.getRight().getIngredient().apply(((TileMicroscope) te).getHandler().getStackInSlot(0)))
{
store.unlockStepAndSync(pair.getLeft().getId(), p);
NetworkManager.sendTo(new CPacketCheckMicroscopeResearchResponse(true), p);
......
......@@ -22,7 +22,7 @@ public abstract class TileAbstractSingleItem extends TileSyncableComposite
public static final String NBT_ITEMS = "items";
public static final String NBT_ITEMS_UPDATE = "items_update";
public ItemStackHandler handler = new ItemStackHandler(1)
private ItemStackHandler handler = new ItemStackHandler(1)
{
@Override
protected void onContentsChanged(int slot)
......@@ -41,6 +41,11 @@ public abstract class TileAbstractSingleItem extends TileSyncableComposite
}
};
public ItemStackHandler getHandler()
{
return handler;
}
public TileAbstractSingleItem()
{
getSerializers().add(new NBTSerializer.ReaderWriter<>(NBT_ITEMS, NBTTagCompound.class, handler::deserializeNBT, handler::serializeNBT));
......@@ -58,7 +63,7 @@ public abstract class TileAbstractSingleItem extends TileSyncableComposite
public <T> T getCapability(Capability<T> capability, @Nullable EnumFacing facing)
{
if (capability == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY)
return CapabilityItemHandler.ITEM_HANDLER_CAPABILITY.cast(handler);
return CapabilityItemHandler.ITEM_HANDLER_CAPABILITY.cast(getHandler());
return super.getCapability(capability, facing);
}
......
......@@ -18,6 +18,7 @@ import net.minecraftforge.fml.relauncher.SideOnly;
import net.minecraftforge.items.CapabilityItemHandler;
import net.minecraftforge.items.ItemStackHandler;
import ru.pearx.lib.HashingUtils;
import ru.pearx.libmc.PXLMC;
import ru.pearx.libmc.common.ItemStackUtils;
import ru.pearx.libmc.common.PXLCapabilities;
import ru.pearx.libmc.common.caps.animation.AnimationElement;
......@@ -51,7 +52,7 @@ public class TileCodeStorage extends TileSyncableComposite
public static final String[] NBT_ITEM_DATA = new String[]{NBT_ITEMS, NBT_TEXT, NBT_HASH, NBT_UNLOCKED};
private boolean lockable;
public ItemStackHandler handler = new ItemStackHandler(ContainerCodeStorage.SLOT_COUNT)
private ItemStackHandler handler = new ItemStackHandler(ContainerCodeStorage.SLOT_COUNT)
{
@Override
protected void onContentsChanged(int slot)
......@@ -93,10 +94,15 @@ public class TileCodeStorage extends TileSyncableComposite
getSerializers().add(new NBTSerializer.ReaderWriter<>(NBT_HASH, byte[].class, this::setHash, this::getHash));
getSerializers().add(new NBTSerializer.ReaderWriter<>(NBT_UNLOCKED, boolean.class, this::setUnlocked, this::isUnlocked));
getSerializers().add(new NBTSerializer.ReaderWriter<>(NBT_OPENED, boolean.class, this::setOpened, this::isOpened, WriteTarget.SAVE));
getSerializers().add(new NBTSerializer.ReaderWriter<>(NBT_OPENED_UPDATE, boolean.class, (Boolean b) -> setOpenedAndUpdate(Minecraft.getMinecraft().player, b), this::isOpened, WriteTarget.PARTIAL_UPDATE));
getSerializers().add(new NBTSerializer.ReaderWriter<>(NBT_OPENED_UPDATE, boolean.class, (Boolean b) -> setOpenedAndUpdate(PXLMC.PROXY.getClientPlayer(), b), this::isOpened, WriteTarget.PARTIAL_UPDATE));
getSerializers().add(new NBTSerializer.Reader<>(NBT_SLOT_UPDATE, NBTTagCompound.class, (tag) -> ItemStackUtils.loadSlotUpdate(tag, handler)));
}
public ItemStackHandler getHandler()
{
return handler;
}
public String getText()
{
return text;
......
package ru.pearx.purmag.common.tiles;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.BlockPos;
import net.minecraftforge.common.capabilities.Capability;
import net.minecraftforge.common.util.Constants;
import net.minecraftforge.items.CapabilityItemHandler;
import net.minecraftforge.items.ItemStackHandler;
import ru.pearx.libmc.common.ItemStackUtils;
import ru.pearx.libmc.common.nbt.NBTTagCompoundBuilder;
import ru.pearx.libmc.common.nbt.serialization.NBTSerializer;
import ru.pearx.libmc.common.structure.multiblock.IMultiblockPart;
import ru.pearx.libmc.common.structure.multiblock.events.MultiblockActivatedEvent;
import ru.pearx.libmc.common.structure.multiblock.events.MultiblockBreakEvent;
......@@ -20,35 +23,43 @@ import javax.annotation.Nullable;
*/
public class TileStoneCrusher extends TilePMMultiblockMaster
{
public static final String NBT_ITEMS = "items";
public static final String NBT_SLOT_UPDATE = "items_update";
public static final String NBT_SPINS = "spins";
public ItemStackHandler handler = new ItemStackHandler()
{
@Override
protected void onContentsChanged(int slot)
{
TileStoneCrusher.this.markDirty();
//sendUpdates(ItemStackUtils.writeSlotUpdate(this, slot, "slotUpdateStack", "slotUpdateStack"), null);
sendUpdates(null, new NBTTagCompoundBuilder().setTag(NBT_SLOT_UPDATE, ItemStackUtils.writeSlotUpdate(this, slot)).build());
}
};
private int spins;
public int getMaxSpins()
public TileStoneCrusher()
{
return 10;
getSerializers().add(new NBTSerializer.ReaderWriter<>(NBT_ITEMS, NBTTagCompound.class, (tag) -> handler.deserializeNBT(tag), () -> handler.serializeNBT()));
getSerializers().add(new NBTSerializer.ReaderWriter<>(NBT_SPINS, int.class, this::setSpins, this::getSpins));
getSerializers().add(new NBTSerializer.Reader<>(NBT_SLOT_UPDATE, NBTTagCompound.class, (tag) -> ItemStackUtils.loadSlotUpdate(tag, handler)));
}
public int getCooldownBetweenSpins()
public int getSpins()
{
return 6;
return spins;
}
@Override
public void readCustomData(NBTTagCompound tag)
public void setSpins(int spins)
{
super.readCustomData(tag);
if (tag.hasKey("items", Constants.NBT.TAG_COMPOUND))
handler.deserializeNBT((NBTTagCompound) tag.getTag("items"));
this.spins = spins;
markDirty();
}
//update only
// ItemStackUtils.loadSlotUpdate(tag, handler, "slotUpdateSlot", "slotUpdateStack");
public void setSpinsAndSync(int spins, EntityPlayer p)
{
setSpins(spins);
sendUpdates(p, NBT_SPINS);
}
@Override
......@@ -69,31 +80,9 @@ public class TileStoneCrusher extends TilePMMultiblockMaster
@Override
public boolean handleActivated(MultiblockActivatedEvent evt, IMultiblockPart part)
{
//elevate the anvil
BlockPos original = getOriginalPos(part.getPos());
/* if (MultiblockRegistry.STONE_CRUSHER.handle.equals(original))
{
long delta = part.getWorld().getTotalWorldTime() - getPreviousAction();
if (getSpins() < getMaxSpins() && (delta < 0 || delta > getCooldownBetweenSpins()))
{
setSpins(getSpins() + 1, true, evt.getPlayer());
setPreviousSpin(part.getWorld().getTotalWorldTime(), true, evt.getPlayer());
return true;
}
}
//drop the anvil
else if (MultiblockRegistry.STONE_CRUSHER.lever.equals(original))
{
if(getSpins() > 0)
{
setCrushes(getCrushes() + getSpins(), true, evt.getPlayer());
setSpins(0, true, evt.getPlayer());
setPreviousSpin(part.getWorld().getTotalWorldTime(), true, evt.getPlayer());
return true;
}
}
//insert the item
else if(MultiblockRegistry.STONE_CRUSHER.anvil.equals(original) && getSpins() > 0)
if(MultiblockRegistry.STONE_CRUSHER.anvil.equals(original) && getSpins() > 0)
{
if(evt.getPlayer().isSneaking())
{
......@@ -113,7 +102,7 @@ public class TileStoneCrusher extends TilePMMultiblockMaster
return true;
}
}
}*/
}
return false;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment