1
0
mirror of https://github.com/SquidDev-CC/CC-Tweaked synced 2025-01-22 06:56:56 +00:00

Share some map-like-item rendering code

Just refactors the hand rendering methods into a shared superclass
This commit is contained in:
SquidDev 2018-12-29 16:42:02 +00:00
parent 8422a40c69
commit 929f23fd2d
14 changed files with 167 additions and 417 deletions

View File

@ -170,20 +170,20 @@ public final class ComputerCraftAPI
} }
/** /**
* Registers a peripheral handler to convert blocks into {@link IPeripheral} implementations. * Registers a peripheral provider to convert blocks into {@link IPeripheral} implementations.
* *
* @param handler The peripheral provider to register. * @param provider The peripheral provider to register.
* @see dan200.computercraft.api.peripheral.IPeripheral * @see dan200.computercraft.api.peripheral.IPeripheral
* @see dan200.computercraft.api.peripheral.IPeripheralProvider * @see dan200.computercraft.api.peripheral.IPeripheralProvider
*/ */
public static void registerPeripheralProvider( @Nonnull IPeripheralProvider handler ) public static void registerPeripheralProvider( @Nonnull IPeripheralProvider provider )
{ {
findCC(); findCC();
if( computerCraft_registerPeripheralProvider != null ) if( computerCraft_registerPeripheralProvider != null )
{ {
try try
{ {
computerCraft_registerPeripheralProvider.invoke( null, handler ); computerCraft_registerPeripheralProvider.invoke( null, provider );
} }
catch( Exception e ) catch( Exception e )
{ {
@ -220,19 +220,19 @@ public final class ComputerCraftAPI
} }
/** /**
* Registers a bundled redstone handler to provide bundled redstone output for blocks. * Registers a bundled redstone provider to provide bundled redstone output for blocks.
* *
* @param handler The bundled redstone provider to register. * @param provider The bundled redstone provider to register.
* @see dan200.computercraft.api.redstone.IBundledRedstoneProvider * @see dan200.computercraft.api.redstone.IBundledRedstoneProvider
*/ */
public static void registerBundledRedstoneProvider( @Nonnull IBundledRedstoneProvider handler ) public static void registerBundledRedstoneProvider( @Nonnull IBundledRedstoneProvider provider )
{ {
findCC(); findCC();
if( computerCraft_registerBundledRedstoneProvider != null ) if( computerCraft_registerBundledRedstoneProvider != null )
{ {
try try
{ {
computerCraft_registerBundledRedstoneProvider.invoke( null, handler ); computerCraft_registerBundledRedstoneProvider.invoke( null, provider );
} }
catch( Exception e ) catch( Exception e )
{ {
@ -269,19 +269,19 @@ public final class ComputerCraftAPI
} }
/** /**
* Registers a media handler to provide {@link IMedia} implementations for Items * Registers a media provider to provide {@link IMedia} implementations for Items
* *
* @param handler The media provider to register. * @param provider The media provider to register.
* @see dan200.computercraft.api.media.IMediaProvider * @see dan200.computercraft.api.media.IMediaProvider
*/ */
public static void registerMediaProvider( @Nonnull IMediaProvider handler ) public static void registerMediaProvider( @Nonnull IMediaProvider provider )
{ {
findCC(); findCC();
if( computerCraft_registerMediaProvider != null ) if( computerCraft_registerMediaProvider != null )
{ {
try try
{ {
computerCraft_registerMediaProvider.invoke( null, handler ); computerCraft_registerMediaProvider.invoke( null, provider );
} }
catch( Exception e ) catch( Exception e )
{ {
@ -291,21 +291,21 @@ public final class ComputerCraftAPI
} }
/** /**
* Registers a permission handler to restrict where turtles can move or build. * Registers a permission provider to restrict where turtles can move or build.
* *
* @param handler The turtle permission provider to register. * @param provider The turtle permission provider to register.
* @see dan200.computercraft.api.permissions.ITurtlePermissionProvider * @see dan200.computercraft.api.permissions.ITurtlePermissionProvider
* @deprecated Prefer using {@link dan200.computercraft.api.turtle.event.TurtleBlockEvent} or the standard Forge events. * @deprecated Prefer using {@link dan200.computercraft.api.turtle.event.TurtleBlockEvent} or the standard Forge events.
*/ */
@Deprecated @Deprecated
public static void registerPermissionProvider( @Nonnull ITurtlePermissionProvider handler ) public static void registerPermissionProvider( @Nonnull ITurtlePermissionProvider provider )
{ {
findCC(); findCC();
if( computerCraft_registerPermissionProvider != null ) if( computerCraft_registerPermissionProvider != null )
{ {
try try
{ {
computerCraft_registerPermissionProvider.invoke( null, handler ); computerCraft_registerPermissionProvider.invoke( null, provider );
} }
catch( Exception e ) catch( Exception e )
{ {

View File

@ -0,0 +1,118 @@
/*
* This file is part of ComputerCraft - http://www.computercraft.info
* Copyright Daniel Ratcliffe, 2011-2018. Do not distribute without permission.
* Send enquiries to dratcliffe@gmail.com
*/
package dan200.computercraft.client.render;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.client.renderer.ItemRenderer;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumHand;
import net.minecraft.util.EnumHandSide;
import net.minecraft.util.math.MathHelper;
public abstract class ItemMapLikeRenderer
{
/**
* The main rendering method for the item
*
* @param stack The stack to render
* @see ItemRenderer#renderMapFirstPerson(ItemStack)
*/
protected abstract void renderItem( ItemStack stack );
protected void renderItemFirstPerson( EnumHand hand, float pitch, float equipProgress, float swingProgress, ItemStack stack )
{
EntityPlayer player = Minecraft.getMinecraft().player;
GlStateManager.pushMatrix();
if( hand == EnumHand.MAIN_HAND && player.getHeldItemOffhand().isEmpty() )
{
renderItemFirstCentre( pitch, equipProgress, swingProgress, stack );
}
else
{
renderItemFirstPersonSide(
hand == EnumHand.MAIN_HAND ? player.getPrimaryHand() : player.getPrimaryHand().opposite(),
equipProgress, swingProgress, stack
);
}
GlStateManager.popMatrix();
}
/**
* Renders the item to one side of the player.
*
* @param side The side to render on
* @param equipProgress The equip progress of this item
* @param swingProgress The swing progress of this item
* @param stack The stack to render
* @see ItemRenderer#renderMapFirstPersonSide(float, EnumHandSide, float, ItemStack)
*/
private void renderItemFirstPersonSide( EnumHandSide side, float equipProgress, float swingProgress, ItemStack stack )
{
Minecraft minecraft = Minecraft.getMinecraft();
float offset = side == EnumHandSide.RIGHT ? 1f : -1f;
GlStateManager.translate( offset * 0.125f, -0.125f, 0f );
// If the player is not invisible then render a single arm
if( !minecraft.player.isInvisible() )
{
GlStateManager.pushMatrix();
GlStateManager.rotate( offset * 10f, 0f, 0f, 1f );
minecraft.getItemRenderer().renderArmFirstPerson( equipProgress, swingProgress, side );
GlStateManager.popMatrix();
}
// Setup the appropriate transformations. This is just copied from the
// corresponding method in ItemRenderer.
GlStateManager.pushMatrix();
GlStateManager.translate( offset * 0.51f, -0.08f + equipProgress * -1.2f, -0.75f );
float f1 = MathHelper.sqrt( swingProgress );
float f2 = MathHelper.sin( f1 * (float) Math.PI );
float f3 = -0.5f * f2;
float f4 = 0.4f * MathHelper.sin( f1 * ((float) Math.PI * 2f) );
float f5 = -0.3f * MathHelper.sin( swingProgress * (float) Math.PI );
GlStateManager.translate( offset * f3, f4 - 0.3f * f2, f5 );
GlStateManager.rotate( f2 * -45f, 1f, 0f, 0f );
GlStateManager.rotate( offset * f2 * -30f, 0f, 1f, 0f );
renderItem( stack );
GlStateManager.popMatrix();
}
/**
* Render an item in the middle of the screen
*
* @param pitch The pitch of the player
* @param equipProgress The equip progress of this item
* @param swingProgress The swing progress of this item
* @param stack The stack to render
* @see ItemRenderer#renderMapFirstPerson(float, float, float)
*/
private void renderItemFirstCentre( float pitch, float equipProgress, float swingProgress, ItemStack stack )
{
ItemRenderer itemRenderer = Minecraft.getMinecraft().getItemRenderer();
// Setup the appropriate transformations. This is just copied from the
// corresponding method in ItemRenderer.
float swingRt = MathHelper.sqrt( swingProgress );
float tX = -0.2f * MathHelper.sin( swingProgress * (float) Math.PI );
float tZ = -0.4f * MathHelper.sin( swingRt * (float) Math.PI );
GlStateManager.translate( 0f, -tX / 2f, tZ );
float pitchAngle = itemRenderer.getMapAngleFromPitch( pitch );
GlStateManager.translate( 0f, 0.04f + equipProgress * -1.2f + pitchAngle * -0.5f, -0.72f );
GlStateManager.rotate( pitchAngle * -85f, 1f, 0f, 0f );
itemRenderer.renderArms();
float rX = MathHelper.sin( swingRt * (float) Math.PI );
GlStateManager.rotate( rX * 20f, 1f, 0f, 0f );
GlStateManager.scale( 2f, 2f, 2f );
renderItem( stack );
}
}

View File

@ -11,17 +11,12 @@ import dan200.computercraft.shared.pocket.items.ItemPocketComputer;
import dan200.computercraft.shared.util.Palette; import dan200.computercraft.shared.util.Palette;
import net.minecraft.client.Minecraft; import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.GlStateManager; import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.client.renderer.ItemRenderer;
import net.minecraft.client.renderer.RenderItem; import net.minecraft.client.renderer.RenderItem;
import net.minecraft.client.renderer.block.model.IBakedModel; import net.minecraft.client.renderer.block.model.IBakedModel;
import net.minecraft.client.renderer.block.model.ItemCameraTransforms; import net.minecraft.client.renderer.block.model.ItemCameraTransforms;
import net.minecraft.client.renderer.texture.TextureManager; import net.minecraft.client.renderer.texture.TextureManager;
import net.minecraft.client.renderer.texture.TextureMap; import net.minecraft.client.renderer.texture.TextureMap;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumHand;
import net.minecraft.util.EnumHandSide;
import net.minecraft.util.math.MathHelper;
import net.minecraftforge.client.ForgeHooksClient; import net.minecraftforge.client.ForgeHooksClient;
import net.minecraftforge.client.event.RenderSpecificHandEvent; import net.minecraftforge.client.event.RenderSpecificHandEvent;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
@ -36,7 +31,7 @@ import static dan200.computercraft.client.gui.FixedWidthFontRenderer.FONT_WIDTH;
* Emulates map rendering for pocket computers * Emulates map rendering for pocket computers
*/ */
@SideOnly( Side.CLIENT ) @SideOnly( Side.CLIENT )
public class ItemPocketRenderer public class ItemPocketRenderer extends ItemMapLikeRenderer
{ {
@SubscribeEvent @SubscribeEvent
public void renderItem( RenderSpecificHandEvent event ) public void renderItem( RenderSpecificHandEvent event )
@ -45,38 +40,11 @@ public class ItemPocketRenderer
if( !(stack.getItem() instanceof ItemPocketComputer) ) return; if( !(stack.getItem() instanceof ItemPocketComputer) ) return;
event.setCanceled( true ); event.setCanceled( true );
renderItemFirstPerson( event.getHand(), event.getInterpolatedPitch(), event.getEquipProgress(), event.getSwingProgress(), event.getItemStack() );
EntityPlayer player = Minecraft.getMinecraft().player;
GlStateManager.pushMatrix();
if( event.getHand() == EnumHand.MAIN_HAND && player.getHeldItemOffhand().isEmpty() )
{
renderItemFirstCentre(
event.getInterpolatedPitch(),
event.getEquipProgress(),
event.getSwingProgress(),
stack
);
}
else
{
renderItemFirstPersonSide(
event.getHand() == EnumHand.MAIN_HAND ? player.getPrimaryHand() : player.getPrimaryHand().opposite(),
event.getEquipProgress(),
event.getSwingProgress(),
stack
);
}
GlStateManager.popMatrix();
} }
/** @Override
* The main rendering method for pocket computers and their associated terminal protected void renderItem( ItemStack stack )
*
* @param stack The stack to render
* @see ItemRenderer#renderMapFirstPerson(ItemStack)
*/
private void renderPocketComputerItem( ItemStack stack )
{ {
// Setup various transformations. Note that these are partially adapated from the corresponding method // Setup various transformations. Note that these are partially adapated from the corresponding method
// in ItemRenderer // in ItemRenderer
@ -190,76 +158,4 @@ public class ItemPocketRenderer
GlStateManager.enableLighting(); GlStateManager.enableLighting();
} }
/**
* Renders a pocket computer to one side of the player.
*
* @param side The side to render on
* @param equipProgress The equip progress of this item
* @param swingProgress The swing progress of this item
* @param stack The stack to render
* @see ItemRenderer#renderMapFirstPersonSide(float, EnumHandSide, float, ItemStack)
*/
private void renderItemFirstPersonSide( EnumHandSide side, float equipProgress, float swingProgress, ItemStack stack )
{
Minecraft minecraft = Minecraft.getMinecraft();
float offset = side == EnumHandSide.RIGHT ? 1f : -1f;
GlStateManager.translate( offset * 0.125f, -0.125f, 0f );
// If the player is not invisible then render a single arm
if( !minecraft.player.isInvisible() )
{
GlStateManager.pushMatrix();
GlStateManager.rotate( offset * 10f, 0f, 0f, 1f );
minecraft.getItemRenderer().renderArmFirstPerson( equipProgress, swingProgress, side );
GlStateManager.popMatrix();
}
// Setup the appropriate transformations. This is just copied from the
// corresponding method in ItemRenderer.
GlStateManager.pushMatrix();
GlStateManager.translate( offset * 0.51f, -0.08f + equipProgress * -1.2f, -0.75f );
float f1 = MathHelper.sqrt( swingProgress );
float f2 = MathHelper.sin( f1 * (float) Math.PI );
float f3 = -0.5f * f2;
float f4 = 0.4f * MathHelper.sin( f1 * ((float) Math.PI * 2f) );
float f5 = -0.3f * MathHelper.sin( swingProgress * (float) Math.PI );
GlStateManager.translate( offset * f3, f4 - 0.3f * f2, f5 );
GlStateManager.rotate( f2 * -45f, 1f, 0f, 0f );
GlStateManager.rotate( offset * f2 * -30f, 0f, 1f, 0f );
renderPocketComputerItem( stack );
GlStateManager.popMatrix();
}
/**
* Render an item in the middle of the screen
*
* @param pitch The pitch of the player
* @param equipProgress The equip progress of this item
* @param swingProgress The swing progress of this item
* @param stack The stack to render
* @see ItemRenderer#renderMapFirstPerson(float, float, float)
*/
private void renderItemFirstCentre( float pitch, float equipProgress, float swingProgress, ItemStack stack )
{
ItemRenderer itemRenderer = Minecraft.getMinecraft().getItemRenderer();
// Setup the appropriate transformations. This is just copied from the
// corresponding method in ItemRenderer.
float swingRt = MathHelper.sqrt( swingProgress );
float tX = -0.2f * MathHelper.sin( swingProgress * (float) Math.PI );
float tZ = -0.4f * MathHelper.sin( swingRt * (float) Math.PI );
GlStateManager.translate( 0f, -tX / 2f, tZ );
float pitchAngle = itemRenderer.getMapAngleFromPitch( pitch );
GlStateManager.translate( 0f, 0.04f + equipProgress * -1.2f + pitchAngle * -0.5f, -0.72f );
GlStateManager.rotate( pitchAngle * -85f, 1f, 0f, 0f );
itemRenderer.renderArms();
float rX = MathHelper.sin( swingRt * (float) Math.PI );
GlStateManager.rotate( rX * 20f, 1f, 0f, 0f );
GlStateManager.scale( 2f, 2f, 2f );
renderPocketComputerItem( stack );
}
} }

View File

@ -2,14 +2,8 @@ package dan200.computercraft.client.render;
import dan200.computercraft.ComputerCraft; import dan200.computercraft.ComputerCraft;
import dan200.computercraft.shared.media.items.ItemPrintout; import dan200.computercraft.shared.media.items.ItemPrintout;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.GlStateManager; import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.client.renderer.ItemRenderer;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumHand;
import net.minecraft.util.EnumHandSide;
import net.minecraft.util.math.MathHelper;
import net.minecraftforge.client.event.RenderItemInFrameEvent; import net.minecraftforge.client.event.RenderItemInFrameEvent;
import net.minecraftforge.client.event.RenderSpecificHandEvent; import net.minecraftforge.client.event.RenderSpecificHandEvent;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
@ -20,7 +14,7 @@ import static dan200.computercraft.client.render.PrintoutRenderer.*;
import static dan200.computercraft.shared.media.items.ItemPrintout.LINES_PER_PAGE; import static dan200.computercraft.shared.media.items.ItemPrintout.LINES_PER_PAGE;
import static dan200.computercraft.shared.media.items.ItemPrintout.LINE_MAX_LENGTH; import static dan200.computercraft.shared.media.items.ItemPrintout.LINE_MAX_LENGTH;
public class ItemPrintoutRenderer public class ItemPrintoutRenderer extends ItemMapLikeRenderer
{ {
@SubscribeEvent @SubscribeEvent
public void onRenderInHand( RenderSpecificHandEvent event ) public void onRenderInHand( RenderSpecificHandEvent event )
@ -30,104 +24,11 @@ public class ItemPrintoutRenderer
event.setCanceled( true ); event.setCanceled( true );
EntityPlayer player = Minecraft.getMinecraft().player; renderItemFirstPerson( event.getHand(), event.getInterpolatedPitch(), event.getEquipProgress(), event.getSwingProgress(), event.getItemStack() );
GlStateManager.pushMatrix();
if( event.getHand() == EnumHand.MAIN_HAND && player.getHeldItemOffhand().isEmpty() )
{
renderPrintoutFirstPersonCentre(
event.getInterpolatedPitch(),
event.getEquipProgress(),
event.getSwingProgress(),
stack
);
}
else
{
renderPrintoutFirstPersonSide(
event.getHand() == EnumHand.MAIN_HAND ? player.getPrimaryHand() : player.getPrimaryHand().opposite(),
event.getEquipProgress(),
event.getSwingProgress(),
stack
);
}
GlStateManager.popMatrix();
} }
/** @Override
* Renders a pocket computer to one side of the player. protected void renderItem( ItemStack stack )
*
* @param side The side to render on
* @param equipProgress The equip progress of this item
* @param swingProgress The swing progress of this item
* @param stack The stack to render
* @see ItemRenderer#renderMapFirstPersonSide(float, EnumHandSide, float, ItemStack)
*/
private void renderPrintoutFirstPersonSide( EnumHandSide side, float equipProgress, float swingProgress, ItemStack stack )
{
Minecraft minecraft = Minecraft.getMinecraft();
float offset = side == EnumHandSide.RIGHT ? 1f : -1f;
GlStateManager.translate( offset * 0.125f, -0.125f, 0f );
// If the player is not invisible then render a single arm
if( !minecraft.player.isInvisible() )
{
GlStateManager.pushMatrix();
GlStateManager.rotate( offset * 10f, 0f, 0f, 1f );
minecraft.getItemRenderer().renderArmFirstPerson( equipProgress, swingProgress, side );
GlStateManager.popMatrix();
}
// Setup the appropriate transformations. This is just copied from the
// corresponding method in ItemRenderer.
GlStateManager.pushMatrix();
GlStateManager.translate( offset * 0.51f, -0.08f + equipProgress * -1.2f, -0.75f );
float f1 = MathHelper.sqrt( swingProgress );
float f2 = MathHelper.sin( f1 * (float) Math.PI );
float f3 = -0.5f * f2;
float f4 = 0.4f * MathHelper.sin( f1 * ((float) Math.PI * 2f) );
float f5 = -0.3f * MathHelper.sin( swingProgress * (float) Math.PI );
GlStateManager.translate( offset * f3, f4 - 0.3f * f2, f5 );
GlStateManager.rotate( f2 * -45f, 1f, 0f, 0f );
GlStateManager.rotate( offset * f2 * -30f, 0f, 1f, 0f );
renderPrintoutFirstPerson( stack );
GlStateManager.popMatrix();
}
/**
* Render an item in the middle of the screen
*
* @param pitch The pitch of the player
* @param equipProgress The equip progress of this item
* @param swingProgress The swing progress of this item
* @param stack The stack to render
* @see ItemRenderer#renderMapFirstPerson(float, float, float)
*/
private void renderPrintoutFirstPersonCentre( float pitch, float equipProgress, float swingProgress, ItemStack stack )
{
ItemRenderer itemRenderer = Minecraft.getMinecraft().getItemRenderer();
// Setup the appropriate transformations. This is just copied from the
// corresponding method in ItemRenderer.
float swingRt = MathHelper.sqrt( swingProgress );
float tX = -0.2f * MathHelper.sin( swingProgress * (float) Math.PI );
float tZ = -0.4f * MathHelper.sin( swingRt * (float) Math.PI );
GlStateManager.translate( 0f, -tX / 2f, tZ );
float pitchAngle = itemRenderer.getMapAngleFromPitch( pitch );
GlStateManager.translate( 0f, 0.04f + equipProgress * -1.2f + pitchAngle * -0.5f, -0.72f );
GlStateManager.rotate( pitchAngle * -85f, 1f, 0f, 0f );
itemRenderer.renderArms();
float rX = MathHelper.sin( swingRt * (float) Math.PI );
GlStateManager.rotate( rX * 20f, 1f, 0f, 0f );
GlStateManager.scale( 2f, 2f, 2f );
renderPrintoutFirstPerson( stack );
}
private static void renderPrintoutFirstPerson( ItemStack stack )
{ {
// Setup various transformations. Note that these are partially adapated from the corresponding method // Setup various transformations. Note that these are partially adapated from the corresponding method
// in ItemRenderer.renderMapFirstPerson // in ItemRenderer.renderMapFirstPerson

View File

@ -96,7 +96,7 @@ public final class ModelTransformer
} }
@Override @Override
public void setQuadOrientation( EnumFacing orientation ) public void setQuadOrientation( @Nonnull EnumFacing orientation )
{ {
super.setQuadOrientation( orientation == null ? orientation : TRSRTransformation.rotate( positionMatrix, orientation ) ); super.setQuadOrientation( orientation == null ? orientation : TRSRTransformation.rotate( positionMatrix, orientation ) );
} }

View File

@ -105,7 +105,7 @@ public class PrintoutRenderer
// Draw centre panel (just stretched texture, sorry). // Draw centre panel (just stretched texture, sorry).
drawTexture( buffer, drawTexture( buffer,
x - offset, y, z - 0.02, X_SIZE + offset * 2, Y_SIZE, x - offset, y, z - 0.02, X_SIZE + offset * 2, Y_SIZE,
COVER_X + COVER_SIZE / 2, COVER_SIZE, COVER_SIZE, Y_SIZE COVER_X + COVER_SIZE / 2.0f, COVER_SIZE, COVER_SIZE, Y_SIZE
); );
double borderX = left; double borderX = left;
@ -119,7 +119,7 @@ public class PrintoutRenderer
} }
// Left half // Left half
drawTexture( buffer, x, y, z, X_FOLD_SIZE * 2, 0, X_SIZE / 2, Y_SIZE ); drawTexture( buffer, x, y, z, X_FOLD_SIZE * 2, 0, X_SIZE / 2.0f, Y_SIZE );
for( int n = 0; n <= leftPages; n++ ) for( int n = 0; n <= leftPages; n++ )
{ {
drawTexture( buffer, drawTexture( buffer,
@ -131,7 +131,7 @@ public class PrintoutRenderer
} }
// Right half // Right half
drawTexture( buffer, x + X_SIZE / 2, y, z, X_FOLD_SIZE * 2 + X_SIZE / 2, 0, X_SIZE / 2, Y_SIZE ); drawTexture( buffer, x + X_SIZE / 2.0f, y, z, X_FOLD_SIZE * 2 + X_SIZE / 2.0f, 0, X_SIZE / 2.0f, Y_SIZE );
for( int n = 0; n <= rightPages; n++ ) for( int n = 0; n <= rightPages; n++ )
{ {
drawTexture( buffer, drawTexture( buffer,

View File

@ -75,25 +75,17 @@ public class TurtleSmartItemModel implements IBakedModel, ISelectiveResourceRelo
@Override @Override
public boolean equals( Object other ) public boolean equals( Object other )
{ {
if( other == this ) if( other == this ) return true;
{ if( !(other instanceof TurtleModelCombination) ) return false;
return true;
} TurtleModelCombination otherCombo = (TurtleModelCombination) other;
if( other instanceof TurtleModelCombination ) return otherCombo.m_family == m_family &&
{ otherCombo.m_colour == m_colour &&
TurtleModelCombination otherCombo = (TurtleModelCombination) other; otherCombo.m_leftUpgrade == m_leftUpgrade &&
if( otherCombo.m_family == m_family && otherCombo.m_rightUpgrade == m_rightUpgrade &&
otherCombo.m_colour == m_colour && Objects.equal( otherCombo.m_overlay, m_overlay ) &&
otherCombo.m_leftUpgrade == m_leftUpgrade && otherCombo.m_christmas == m_christmas &&
otherCombo.m_rightUpgrade == m_rightUpgrade && otherCombo.m_flip == m_flip;
Objects.equal( otherCombo.m_overlay, m_overlay ) &&
otherCombo.m_christmas == m_christmas &&
otherCombo.m_flip == m_flip )
{
return true;
}
}
return false;
} }
@Override @Override

View File

@ -157,12 +157,8 @@ public class AddressPredicate
if( matchesAddress( address ) ) return true; if( matchesAddress( address ) ) return true;
// If we're an IPv4 address in disguise then let's check that. // If we're an IPv4 address in disguise then let's check that.
if( address instanceof Inet6Address && InetAddresses.is6to4Address( (Inet6Address) address ) return address instanceof Inet6Address && InetAddresses.is6to4Address( (Inet6Address) address )
&& matchesAddress( InetAddresses.get6to4IPv4Address( (Inet6Address) address ) ) ) && matchesAddress( InetAddresses.get6to4IPv4Address( (Inet6Address) address ) );
{
return true;
}
return false;
} }
} }

View File

@ -1,135 +0,0 @@
/*
* This file is part of ComputerCraft - http://www.computercraft.info
* Copyright Daniel Ratcliffe, 2011-2017. Do not distribute without permission.
* Send enquiries to dratcliffe@gmail.com
*/
package dan200.computercraft.core.apis;
import dan200.computercraft.api.lua.ILuaAPI;
import dan200.computercraft.api.lua.ILuaContext;
import dan200.computercraft.api.lua.ILuaObject;
import dan200.computercraft.api.lua.LuaException;
import dan200.computercraft.core.terminal.TextBuffer;
import javax.annotation.Nonnull;
import static dan200.computercraft.core.apis.ArgumentHelper.getString;
import static dan200.computercraft.core.apis.ArgumentHelper.optInt;
public class BufferAPI implements ILuaAPI
{
private static class BufferLuaObject implements ILuaObject
{
private TextBuffer m_buffer;
public BufferLuaObject( TextBuffer buffer )
{
m_buffer = buffer;
}
@Nonnull
@Override
public String[] getMethodNames()
{
return new String[] {
"len",
"tostring",
"read",
"write",
"fill"
};
}
@Override
public Object[] callMethod( @Nonnull ILuaContext context, int method, @Nonnull Object[] arguments ) throws LuaException, InterruptedException
{
switch( method )
{
case 0:
{
// len
return new Object[] { m_buffer.length() };
}
case 1:
{
// tostring
return new Object[] { m_buffer.toString() };
}
case 2:
{
// read
int start = optInt( arguments, 0, 0 );
int end = optInt( arguments, 1, m_buffer.length() );
return new Object[] { m_buffer.read( start, end ) };
}
case 3:
{
// write
String text = getString( arguments, 0 );
int start = optInt( arguments, 1, 0 );
int end = optInt( arguments, 2, start + text.length() );
m_buffer.write( text, start, end );
return null;
}
case 4:
{
// fill
String text = getString( arguments, 0 );
int start = optInt( arguments, 1, 0 );
int end = optInt( arguments, 2, m_buffer.length() );
m_buffer.fill( text, start, end );
return null;
}
default:
{
return null;
}
}
}
}
public BufferAPI( IAPIEnvironment _env )
{
}
@Override
public String[] getNames()
{
return new String[] {
"buffer"
};
}
@Nonnull
@Override
public String[] getMethodNames()
{
return new String[] {
"new"
};
}
@Override
public Object[] callMethod( @Nonnull ILuaContext context, int method, @Nonnull Object[] arguments ) throws LuaException, InterruptedException
{
switch( method )
{
case 0:
{
String text = getString( arguments, 0 );
int repetitions = optInt( arguments, 1, 1 );
if( repetitions < 0 )
{
throw ArgumentHelper.badArgument( 1, "positive number", Integer.toString( repetitions ) );
}
TextBuffer buffer = new TextBuffer( text, repetitions );
return new Object[] { new BufferLuaObject( buffer ) };
}
default:
{
return null;
}
}
}
}

View File

@ -198,7 +198,7 @@ public class HTTPAPI implements ILuaAPI
String address = getString( args, 0 ); String address = getString( args, 0 );
Map<Object, Object> headerTbl = optTable( args, 1, Collections.emptyMap() ); Map<Object, Object> headerTbl = optTable( args, 1, Collections.emptyMap() );
HashMap<String, String> headers = new HashMap<String, String>( headerTbl.size() ); HashMap<String, String> headers = new HashMap<>( headerTbl.size() );
for( Object key : headerTbl.keySet() ) for( Object key : headerTbl.keySet() )
{ {
Object value = headerTbl.get( key ); Object value = headerTbl.get( key );

View File

@ -55,18 +55,7 @@ public class OSAPI implements ILuaAPI
{ {
double t = m_day * 24.0 + m_time; double t = m_day * 24.0 + m_time;
double ot = m_day * 24.0 + m_time; double ot = m_day * 24.0 + m_time;
if( t < ot ) return Double.compare( t, ot );
{
return -1;
}
else if( t > ot )
{
return 1;
}
else
{
return 0;
}
} }
} }

View File

@ -714,7 +714,6 @@ public class Computer
m_apis.add( new FSAPI( m_apiEnvironment ) ); m_apis.add( new FSAPI( m_apiEnvironment ) );
m_apis.add( new PeripheralAPI( m_apiEnvironment ) ); m_apis.add( new PeripheralAPI( m_apiEnvironment ) );
m_apis.add( new OSAPI( m_apiEnvironment ) ); m_apis.add( new OSAPI( m_apiEnvironment ) );
//m_apis.add( new BufferAPI( m_apiEnvironment ) );
if( ComputerCraft.http_enable ) if( ComputerCraft.http_enable )
{ {
m_apis.add( new HTTPAPI( m_apiEnvironment ) ); m_apis.add( new HTTPAPI( m_apiEnvironment ) );

View File

@ -34,14 +34,9 @@ public class ContainerHeldItem extends Container
@Override @Override
public boolean canInteractWith( @Nonnull EntityPlayer player ) public boolean canInteractWith( @Nonnull EntityPlayer player )
{ {
if( player != null && player.isEntityAlive() ) if( player == null || !player.isEntityAlive() ) return false;
{
ItemStack stack = player.getHeldItem( m_hand ); ItemStack stack = player.getHeldItem( m_hand );
if( (stack == m_stack) || (!stack.isEmpty() && !m_stack.isEmpty() && stack.getItem() == m_stack.getItem()) ) return (stack == m_stack) || (!stack.isEmpty() && !m_stack.isEmpty() && stack.getItem() == m_stack.getItem());
{
return true;
}
}
return false;
} }
} }

View File

@ -402,9 +402,8 @@ public abstract class ComputerCraftProxyCommon implements IComputerCraftProxy
// Client messages // Client messages
NetworkMessage.registerMainThread( Side.CLIENT, PlayRecordClientMessage::new, ( computer, packet ) -> { NetworkMessage.registerMainThread( Side.CLIENT, PlayRecordClientMessage::new, ( computer, packet ) ->
playRecordClient( packet.getPos(), packet.getSoundEvent(), packet.getName() ); playRecordClient( packet.getPos(), packet.getSoundEvent(), packet.getName() ) );
} );
ComputerClientMessage.register( ComputerDataClientMessage::new, ( computer, packet ) -> ComputerClientMessage.register( ComputerDataClientMessage::new, ( computer, packet ) ->
computer.setState( packet.getState(), packet.getUserData() ) ); computer.setState( packet.getState(), packet.getUserData() ) );