Commit 8d0fb5de authored by mrAppleXZ's avatar mrAppleXZ 💾

Stone Crusher work

parent 6ac6b9b8
......@@ -9,9 +9,11 @@ import net.minecraft.util.math.MathHelper;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import org.lwjgl.opengl.GL11;
import ru.pearx.lib.math.MathUtils;
import ru.pearx.libmc.PXLMC;
import ru.pearx.libmc.client.ModelSupplied;
import ru.pearx.libmc.client.PXLFastTESR;
import ru.pearx.libmc.client.TESRMultiblock;
import ru.pearx.libmc.client.models.PXLModelRenderer;
import ru.pearx.purmag.common.Utils;
import ru.pearx.purmag.common.tiles.TileStoneCrusher;
......@@ -20,7 +22,7 @@ import ru.pearx.purmag.common.tiles.TileStoneCrusher;
* Created by mrAppleXZ on 12.12.17 19:22.
*/
@SideOnly(Side.CLIENT)
public class TESRStoneCrusher extends PXLFastTESR<TileStoneCrusher>
public class TESRStoneCrusher extends TESRMultiblock<TileStoneCrusher>
{
public static final ModelSupplied MDL_MAIN = new ModelSupplied(new ModelResourceLocation(Utils.gRL("stone_crusher/main"), "normal"));
public static final ModelSupplied MDL_LEVER = new ModelSupplied(new ModelResourceLocation(Utils.gRL("stone_crusher/lever"), "normal"));
......@@ -54,33 +56,42 @@ public class TESRStoneCrusher extends PXLFastTESR<TileStoneCrusher>
tes.draw();
GlStateManager.popMatrix();
GlStateManager.pushMatrix();
resetTrans(te);
GlStateManager.translate(0.5, 0.5, 0);
GlStateManager.rotate(deg, 0, 0, 1);
GlStateManager.translate(-0.5, -0.5, 0);
setTrans(te);
buffer.begin(GL11.GL_QUADS, DefaultVertexFormats.BLOCK);
PXLModelRenderer.renderModelTESR(te.getWorld(), MDL_HANDLE.get(), te.getWorld().getBlockState(te.getPos()), te.getPos(), buffer, false, MathHelper.getPositionRandom(te.getPos()));
tes.draw();
GlStateManager.popMatrix();
{
long timeDelta = te.getWorld().getTotalWorldTime() - te.getPreviousSpin();
float rot = timeDelta > te.getCooldownBetweenSpins() ? te.getSpins() * 90 : (te.getSpins() - 1) * 90 + timeDelta * (90f / te.getCooldownBetweenSpins());
GlStateManager.pushMatrix();
resetTrans(te);
GlStateManager.translate(0.5, 0.5, 0);
GlStateManager.rotate(rot, 0, 0, 1);
GlStateManager.translate(-0.5, -0.5, 0);
setTrans(te);
buffer.begin(GL11.GL_QUADS, DefaultVertexFormats.BLOCK);
PXLModelRenderer.renderModelTESR(te.getWorld(), MDL_HANDLE.get(), te.getWorld().getBlockState(te.getPos()), te.getPos(), buffer, false, MathHelper.getPositionRandom(te.getPos()));
tes.draw();
GlStateManager.popMatrix();
GlStateManager.pushMatrix();
resetTrans(te);
GlStateManager.translate(0.5, 0.5, -0.5);
GlStateManager.rotate(deg, 0, 0, 1);
GlStateManager.translate(-0.5, -0.5, 0.5);
setTrans(te);
buffer.begin(GL11.GL_QUADS, DefaultVertexFormats.BLOCK);
PXLModelRenderer.renderModelTESR(te.getWorld(), MDL_COIL.get(), te.getWorld().getBlockState(te.getPos()), te.getPos(), buffer, false, MathHelper.getPositionRandom(te.getPos()));
tes.draw();
GlStateManager.popMatrix();
GlStateManager.pushMatrix();
resetTrans(te);
GlStateManager.translate(0.5, 0.5, -0.5);
GlStateManager.rotate(rot, 0, 0, 1);
GlStateManager.translate(-0.5, -0.5, 0.5);
setTrans(te);
buffer.begin(GL11.GL_QUADS, DefaultVertexFormats.BLOCK);
PXLModelRenderer.renderModelTESR(te.getWorld(), MDL_COIL.get(), te.getWorld().getBlockState(te.getPos()), te.getPos(), buffer, false, MathHelper.getPositionRandom(te.getPos()));
tes.draw();
GlStateManager.popMatrix();
}
GlStateManager.pushMatrix();
GlStateManager.translate(1, 0, 0);
float anvilY = (float)te.getSpins() / te.getMaxSpins();
boolean onGround = te.getSpins() <= 0;
float anvilXMod = onGround ? 0 : MathHelper.sin(MathUtils.toRadians((System.currentTimeMillis() / 10) % 360)) * 0.2f * (1 - anvilY);
GlStateManager.translate(1 + anvilXMod, anvilY, 0);
buffer.begin(GL11.GL_QUADS, DefaultVertexFormats.BLOCK);
Minecraft.getMinecraft().getBlockRendererDispatcher().getBlockModelRenderer().renderModel(te.getWorld(), MDL_ANVIL.get(), te.getWorld().getBlockState(te.getPos()), te.getPos(), buffer, false, MathHelper.getPositionRandom(te.getPos()));
tes.draw();
buffer.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION_TEX);
tes.draw();
GlStateManager.popMatrix();
GlStateManager.popMatrix();
......
......@@ -52,4 +52,6 @@ public class PMMultiblock extends Multiblock
}
return super.checkMultiblock(w, pos, p, hand);
}
}
......@@ -56,14 +56,12 @@ public class ItemTinkeringKit extends ItemToolBase
{
if(mb instanceof PMMultiblock)
{
Optional<Rotation> rot = mb.tryForm(worldIn, pos, player, hand);
Optional<Rotation> rot = mb.checkMultiblock(worldIn, pos, player, hand);
if (rot.isPresent())
{
player.getHeldItem(hand).damageItem(1, player);
if (!worldIn.isRemote)
{
NetworkManager.sendToAllAround(new CPacketSpawnMultiblockParticles(pos, mb.getRegistryName(), rot.get()), pos.getX(), pos.getY(), pos.getZ(), worldIn.provider.getDimension(), 256);
}
if(!worldIn.isRemote)
mb.form(worldIn, pos, rot.get(), player);
return EnumActionResult.PASS;
}
}
......
......@@ -23,7 +23,7 @@ public abstract class TileAbstractSingleItem extends TileSyncable
protected void onContentsChanged(int slot)
{
TileAbstractSingleItem.this.markDirty();
sendUpdates(new NBTTagCompoundBuilder().setTag("items", serializeNBT()).build());
sendUpdates(new NBTTagCompoundBuilder().setTag("items", serializeNBT()).build(), null);
}
@Nonnull
......
......@@ -175,7 +175,7 @@ public class TileCodeStorage extends TileSyncable
setUnlocked(true);
setHash(null);
setText(null);
sendUpdates(serializeLockUpdate(new NBTTagCompound()));
sendUpdates(serializeLockUpdate(new NBTTagCompound()), null);
return true;
}
return false;
......@@ -192,7 +192,7 @@ public class TileCodeStorage extends TileSyncable
setText(text);
setCode(code);
setUnlocked(false);
sendUpdates(serializeLockUpdate(new NBTTagCompound()));
sendUpdates(serializeLockUpdate(new NBTTagCompound()), null);
return true;
}
}
......
......@@ -45,7 +45,7 @@ public class TileMagibench extends TileSyncable
protected void onContentsChanged(int slot)
{
TileMagibench.this.markDirty();
sendUpdates(new NBTTagCompoundBuilder().setTag("items", serializeNBT()).build());
sendUpdates(new NBTTagCompoundBuilder().setTag("items", serializeNBT()).build(), null);
}
}
......@@ -68,7 +68,7 @@ public class TileMagibench extends TileSyncable
this.tier = tier;
handler = new Handler(t.getWidth() * t.getHeight());
if(sync)
sendUpdates(new NBTTagCompoundBuilder().setInteger("tier", tier).build());
sendUpdates(new NBTTagCompoundBuilder().setInteger("tier", tier).build(), null);
}
@Nullable
......
package ru.pearx.purmag.common.tiles;
import net.minecraft.entity.player.EntityPlayer;
import ru.pearx.libmc.PXLMC;
import ru.pearx.libmc.common.tiles.TileMultiblockMaster;
import ru.pearx.purmag.common.networking.NetworkManager;
import ru.pearx.purmag.common.networking.packets.CPacketSpawnMultiblockParticles;
import javax.annotation.Nullable;
/*
* Created by mrAppleXZ on 23.02.18 14:51.
*/
public class TilePMMultiblockMaster extends TileMultiblockMaster
{
@Override
public void postForm(@Nullable EntityPlayer p)
{
NetworkManager.sendToAllAround(new CPacketSpawnMultiblockParticles(getZeroPos(), getMultiblock().getRegistryName(), getRotation()), pos.getX(), pos.getY(), pos.getZ(), getWorld().provider.getDimension(), 256);
}
}
......@@ -22,7 +22,7 @@ public class TileSingleSip extends TileSyncable
this.type = type;
markDirty();
if (sync)
sendUpdates(new NBTTagCompoundBuilder().setString("sip_type", type).build());
sendUpdates(new NBTTagCompoundBuilder().setString("sip_type", type).build(), null);
}
@Override
......
package ru.pearx.purmag.common.tiles;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.ITickable;
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.nbt.NBTTagCompoundBuilder;
import ru.pearx.libmc.common.structure.multiblock.IMultiblockPart;
import ru.pearx.libmc.common.structure.multiblock.Multiblock;
import ru.pearx.libmc.common.structure.multiblock.events.MultiblockActivatedEvent;
import ru.pearx.libmc.common.tiles.TileMultiblockMaster;
import ru.pearx.purmag.common.blocks.multiblock.MultiblockRegistry;
import scala.reflect.api.Trees;
import javax.annotation.Nullable;
/*
* Created by mrAppleXZ on 16.11.17 20:31.
*/
public class TileStoneCrusher extends TileMultiblockMaster
public class TileStoneCrusher extends TilePMMultiblockMaster
{
public ItemStackHandler handler = new ItemStackHandler()
{
......@@ -22,10 +31,83 @@ public class TileStoneCrusher extends TileMultiblockMaster
protected void onContentsChanged(int slot)
{
TileStoneCrusher.this.markDirty();
sendUpdates(new NBTTagCompoundBuilder().setTag("items", serializeNBT()).build());
sendUpdates(new NBTTagCompoundBuilder().setTag("items", serializeNBT()).build(), null);
}
};
private int crushes;
private int spins;
private long previousSpin;
public int getCrushes()
{
return crushes;
}
public void setCrushes(int crushes, boolean sync)
{
this.crushes = crushes;
if(sync)
sendUpdates(new NBTTagCompoundBuilder().setInteger("crushes", crushes).build(), null);
}
public int getSpins()
{
return spins;
}
public int getMaxSpins()
{
return 10;
}
public int getCooldownBetweenSpins()
{
return 6;
}
public void setSpins(int spins, boolean sync, EntityPlayer p)
{
this.spins = spins;
if(sync)
sendUpdates(new NBTTagCompoundBuilder().setInteger("spins", spins).build(), p);
}
public long getPreviousSpin()
{
return previousSpin;
}
public void setPreviousSpin(long previousSpin, boolean sync, EntityPlayer p)
{
this.previousSpin = previousSpin;
if(sync)
sendUpdates(new NBTTagCompoundBuilder().setLong("previousSpin", previousSpin).build(), p);
}
@Override
public void readCustomData(NBTTagCompound tag)
{
super.readCustomData(tag);
if (tag.hasKey("items", Constants.NBT.TAG_COMPOUND))
handler.deserializeNBT((NBTTagCompound) tag.getTag("items"));
if(tag.hasKey("crushes", Constants.NBT.TAG_INT))
setCrushes(tag.getInteger("crushes"), false);
if(tag.hasKey("spins", Constants.NBT.TAG_INT))
setSpins(tag.getInteger("spins"), false, null);
if(tag.hasKey("previousSpin", Constants.NBT.TAG_LONG))
setPreviousSpin(tag.getLong("previousSpin"), false, null);
}
@Override
public void writeCustomData(NBTTagCompound tag)
{
super.writeCustomData(tag);
tag.setTag("items", handler.serializeNBT());
tag.setInteger("crushes", getCrushes());
tag.setInteger("spins", getSpins());
}
@Override
public boolean hasCapability(Capability<?> capability, @Nullable EnumFacing facing)
{
......@@ -41,19 +123,28 @@ public class TileStoneCrusher extends TileMultiblockMaster
return super.getCapability(capability, facing);
}
@Override
public NBTTagCompound writeToNBT(NBTTagCompound compound)
{
super.writeToNBT(compound);
compound.setTag("items", handler.serializeNBT());
return compound;
}
@Override
public void readFromNBT(NBTTagCompound compound)
public boolean handleActivated(MultiblockActivatedEvent evt, IMultiblockPart part)
{
super.readFromNBT(compound);
if (compound.hasKey("items", Constants.NBT.TAG_COMPOUND))
handler.deserializeNBT((NBTTagCompound) compound.getTag("items"));
//elevate the anvil
BlockPos original = getOriginalPos(part.getPos());
if (MultiblockRegistry.STONE_CRUSHER.handle.equals(original))
{
long delta = part.getWorld().getTotalWorldTime() - getPreviousSpin();
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
if (MultiblockRegistry.STONE_CRUSHER.lever.equals(original))
{
}
return false;
}
}
......@@ -24,7 +24,7 @@ public class TileWallIfTablet extends TileSyncable
markDirty();
if (sync)
sendUpdates(new NBTTagCompoundBuilder().setInteger("tier", tier).build());
sendUpdates(new NBTTagCompoundBuilder().setInteger("tier", tier).build(), null);
}
@Override
......
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