Skip to content

Commit

Permalink
Improve early exit tests on the attach capability event. Hopefully pr…
Browse files Browse the repository at this point in the history
…events a reported crash with Mekanism.
  • Loading branch information
gigaherz committed Jul 27, 2016
1 parent adbca29 commit 836338d
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 79 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ repositories {

apply plugin: 'net.minecraftforge.gradle.forge'

version = "1.5.2"
version = "1.5.3"
group= "gigaherz.survivalist" // http://maven.apache.org/guides/mini/guide-naming-conventions.html
archivesBaseName = "Survivalist-1.10.2"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,73 +5,49 @@
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.client.renderer.block.model.ItemCameraTransforms;
import net.minecraft.client.renderer.texture.TextureMap;
import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
import net.minecraft.item.ItemStack;
import net.minecraftforge.items.CapabilityItemHandler;
import net.minecraftforge.items.IItemHandler;
import org.lwjgl.opengl.GL11;

public class RenderChoppingBlock extends TileEntitySpecialRenderer<TileChopping>
{
final Minecraft mc = Minecraft.getMinecraft();

@Override
public void renderTileEntityAt(TileChopping te, double x, double y, double z, float partialTicks, int destroyStage)
{
IBlockState state = te.getWorld().getBlockState(te.getPos());
if (state.getBlock() != Survivalist.chopping_block)
return;

if (destroyStage >= 0)
{
this.bindTexture(DESTROY_STAGES[destroyStage]);
GlStateManager.matrixMode(GL11.GL_TEXTURE);
GlStateManager.pushMatrix();
GlStateManager.scale(8, 8, 1);
GlStateManager.matrixMode(GL11.GL_MODELVIEW);
}
else
{
bindTexture(TextureMap.LOCATION_BLOCKS_TEXTURE);
}

GlStateManager.disableLighting();

IItemHandler inv = te.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null);

GlStateManager.pushMatrix();

GlStateManager.translate(x + 0.5, y + 0.65, z + 0.5);

ItemStack stack = inv.getStackInSlot(0);
if (stack != null)
if (destroyStage < 0)
{
GlStateManager.disableLighting();
GlStateManager.pushMatrix();
GlStateManager.translate(x + 0.5, y + 0.65, z + 0.5);

IItemHandler inv = te.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null);
ItemStack stack = inv.getStackInSlot(0);
if (stack != null)
{
GlStateManager.pushMatrix();
GlStateManager.translate(0, -4.5 / 16.0f, 0);
GlStateManager.scale(2, 2, 2);
GlStateManager.color(1f, 1f, 1f, 1f);

mc.getRenderItem().renderItem(stack, ItemCameraTransforms.TransformType.GROUND);
/*int breakStage = te.getBreakStage();
if (breakStage >= 0)
{
renderItem(stack, ItemCameraTransforms.TransformType.GROUND, breakStage);
}*/

GlStateManager.popMatrix();
}

GlStateManager.translate(0, -4.5 / 16.0f, 0);

GlStateManager.scale(2, 2, 2);

GlStateManager.color(1f, 1f, 1f, 1f);

Minecraft mc = Minecraft.getMinecraft();
if (destroyStage >= 0)
mc.renderEngine.bindTexture(DESTROY_STAGES[destroyStage]);
else
mc.renderEngine.bindTexture(TextureMap.LOCATION_BLOCKS_TEXTURE);
mc.getRenderItem().renderItem(stack, ItemCameraTransforms.TransformType.GROUND);

GlStateManager.popMatrix();
}

GlStateManager.popMatrix();

GlStateManager.enableLighting();

if (destroyStage >= 0)
{
GlStateManager.matrixMode(GL11.GL_TEXTURE);
GlStateManager.popMatrix();
GlStateManager.matrixMode(GL11.GL_MODELVIEW);
GlStateManager.enableLighting();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import com.google.common.collect.Lists;
import gigaherz.survivalist.Survivalist;
import net.minecraft.block.state.IBlockState;
import net.minecraft.client.particle.ParticleDigging;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Items;
Expand All @@ -14,7 +13,6 @@
import net.minecraft.network.play.server.SPacketUpdateTileEntity;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.ITickable;
import net.minecraft.util.SoundCategory;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
Expand Down Expand Up @@ -255,4 +253,11 @@ public ItemStackHandler getSlotInventory()
{
return slotInventory;
}

public int getBreakStage()
{
if (breakingProgress <= 0)
return -1;
return breakingProgress * 10 / 200;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -293,38 +293,38 @@ public void attachCapabilities(AttachCapabilitiesEvent.Entity e)
{
final Entity entity = e.getEntity();

if (entity.worldObj.isRemote)
if (!(entity instanceof EntityPlayer))
return;

if (entity instanceof EntityPlayer)
if (entity.worldObj == null || entity.worldObj.isRemote)
return;

if (entity.hasCapability(TRACKER, null))
return;

e.addCapability(PROP_KEY, new ICapabilityProvider()
{
if (!entity.hasCapability(TRACKER, null))
ItemBreakingTracker cap = new ItemBreakingTracker();

{
e.addCapability(PROP_KEY, new ICapabilityProvider()
{
ItemBreakingTracker cap = new ItemBreakingTracker();

{
cap.init(entity, entity.worldObj);
}

@Override
public boolean hasCapability(Capability<?> capability, EnumFacing facing)
{
return capability == TRACKER;
}

@SuppressWarnings("unchecked")
@Override
public <T> T getCapability(Capability<T> capability, EnumFacing facing)
{
if (capability == TRACKER)
return (T) cap;
return null;
}
});
cap.init(entity, entity.worldObj);
}
}

@Override
public boolean hasCapability(Capability<?> capability, EnumFacing facing)
{
return capability == TRACKER;
}

@SuppressWarnings("unchecked")
@Override
public <T> T getCapability(Capability<T> capability, EnumFacing facing)
{
if (capability == TRACKER)
return (T) cap;
return null;
}
});
}
}

Expand Down

0 comments on commit 836338d

Please sign in to comment.