Skip to content

Commit

Permalink
Make computer API calls not raise exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
gcewing committed Feb 23, 2016
1 parent e443e2b commit b6eba61
Show file tree
Hide file tree
Showing 17 changed files with 132 additions and 128 deletions.
4 changes: 0 additions & 4 deletions src/base/gcewing/sg/BaseBlock.java
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,6 @@ protected void addProperty(IProperty property) {
int i = numProperties++;
properties[i] = property;
Object[] values = BaseUtils.arrayOf(property.getAllowedValues());
//Arrays.sort(values);
propertyValues[i] = values;
}
else
Expand Down Expand Up @@ -213,15 +212,12 @@ public int getMetaFromState(IBlockState state) {
for (int i = numProperties - 1; i >= 0; i--) {
Object value = state.getValue(properties[i]);
Object[] values = propertyValues[i];
//int k = Arrays.binarySearch(values, value);
int k = values.length - 1;
while (k > 0 && !values[k].equals(value))
--k;
if (debugState)
System.out.printf("BaseBlock.getMetaFromState: property %s value %s --> %s of %s\n",
i, value, k, values.length);
//if (k < 0)
// k = 0;
meta = meta * values.length + k;
}
if (debugState)
Expand Down
37 changes: 17 additions & 20 deletions src/base/gcewing/sg/BaseModClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -337,11 +337,10 @@ GuiScreen getGuiScreen(int id, EntityPlayer player, World world, BlockPos pos, i
public interface ICustomRenderer {
void renderBlock(IBlockAccess world, BlockPos pos, IBlockState state, IRenderTarget target,
EnumWorldBlockLayer layer, Trans3 t);
void renderItemStack(ItemStack stack, IRenderTarget target);
void renderItemStack(ItemStack stack, IRenderTarget target, Trans3 t);
}

public interface ITexture {
//TextureAtlasSprite getIcon();
ResourceLocation location();
int tintIndex();
double red();
Expand Down Expand Up @@ -512,6 +511,11 @@ protected ItemRenderDispatcher getItemRenderDispatcher() {

protected static BaseGLRenderTarget glTarget = new BaseGLRenderTarget();

protected static Trans3 entityTrans = Trans3.blockCenter;
protected static Trans3 equippedTrans = Trans3.blockCenter;
protected static Trans3 firstPersonTrans = Trans3.blockCenterSideTurn(0, 3);
protected static Trans3 inventoryTrans = Trans3.blockCenter;

protected class ItemRenderDispatcher implements IItemRenderer {

public boolean handleRenderType(ItemStack item, ItemRenderType type) {
Expand All @@ -523,21 +527,6 @@ public boolean shouldUseRenderHelper(ItemRenderType type, ItemStack item, ItemRe
}

public void renderItem(ItemRenderType type, ItemStack stack, Object... data) {
// EntityLiving entity = null;
// RenderBlocks rb = null;
switch (type) {
case ENTITY:
case EQUIPPED:
case EQUIPPED_FIRST_PERSON:
// rb = (RenderBlocks)data[0];
// entity = (EntityLiving)data[1];
// break;
case INVENTORY:
// rb = (RenderBlocks)data[0];
break;
default:
return;
}
if (debugRenderItem) System.out.printf("BaseModClient.ItemRenderDispatcher.renderItem: %s %s\n", type, stack);
ICustomRenderer renderer = itemRenderers.get(stack.getItem());
if (debugRenderItem) System.out.printf("BaseModClient.ItemRenderDispatcher.renderItem: Custom renderer = %s\n", renderer);
Expand All @@ -546,8 +535,16 @@ public void renderItem(ItemRenderType type, ItemStack stack, Object... data) {
if (debugRenderItem) System.out.printf("BaseModClient.ItemRenderDispatcher.renderItem: Model renderer = %s\n", renderer);
}
if (renderer != null) {
Trans3 t;
switch (type) {
case ENTITY: t = entityTrans; break;
case EQUIPPED: t = equippedTrans; break;
case EQUIPPED_FIRST_PERSON: t = firstPersonTrans; break;
case INVENTORY: t = inventoryTrans; break;
default: return;
}
glTarget.start(false);
renderer.renderItemStack(stack, glTarget);
renderer.renderItemStack(stack, glTarget, t);
glTarget.finish();
}
}
Expand Down Expand Up @@ -632,11 +629,11 @@ public void renderBlockUsingModelSpec(IBlockAccess world, BlockPos pos, IBlockSt
}

// Call this from renderItemStack of an ICustomRenderer to fall back to model spec
public void renderItemStackUsingModelSpec(ItemStack stack, IRenderTarget target) {
public void renderItemStackUsingModelSpec(ItemStack stack, IRenderTarget target, Trans3 t) {
ICustomRenderer rend = getModelRendererForItemStack(stack);
if (debugRenderItem) System.out.printf("BaseModClient.renderItemStackUsingModelSpec: renderer = %s\n", rend);
if (rend != null)
rend.renderItemStack(stack, target);
rend.renderItemStack(stack, target, t);
}

public IModel getModel(String name) {
Expand Down
6 changes: 3 additions & 3 deletions src/base/gcewing/sg/BaseModelRenderer.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public class BaseModelRenderer implements ICustomRenderer {
protected ITexture[] textures;
protected Vector3 origin;

private static Trans3 itemTrans = Trans3.blockCenterSideTurn(0, 0);
// private static Trans3 itemTrans = Trans3.blockCenterSideTurn(0, 0);

public BaseModelRenderer(IModel model, ITexture... textures) {
this(model, Vector3.zero, textures);
Expand All @@ -42,14 +42,14 @@ public void renderBlock(IBlockAccess world, BlockPos pos, IBlockState state, IRe
model.render(t2, target, textures);
}

public void renderItemStack(ItemStack stack, IRenderTarget target) {
public void renderItemStack(ItemStack stack, IRenderTarget target, Trans3 t) {
if (debugRenderModel) {
System.out.printf("BaseModelRenderer.renderItemStack: %s\n", stack);
System.out.printf("BaseModelRenderer.renderItemStack: model = %s\n", model);
for (int i = 0; i < textures.length; i++)
System.out.printf("BaseModelRenderer.renderItemStack: textures[%s] = %s\n", i, textures[i]);
}
model.render(itemTrans.translate(origin), target, textures);
model.render(t.translate(origin), target, textures);
}

}
Expand Down
5 changes: 3 additions & 2 deletions src/base/gcewing/sg/BaseOrientation.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@

public class BaseOrientation {

public static boolean debugPlacement = true;
public static boolean debugPlacement = false;
public static boolean debugOrientation = false;

public static IOrientationHandler orient4WaysByState = new Orient4WaysByState();
public static IOrientationHandler orient24WaysByTE = new Orient24WaysByTE();
Expand Down Expand Up @@ -50,7 +51,7 @@ protected EnumFacing getHorizontalFacing(Entity entity) {

public Trans3 localToGlobalTransformation(IBlockAccess world, BlockPos pos, IBlockState state, Vector3 origin) {
EnumFacing f = (EnumFacing)state.getValue(FACING);
if (BaseModClient.debugRenderBlock)
if (debugOrientation)
System.out.printf("BaseOrientation.Orient4WaysByState.localToGlobalTransformation: for %s: facing = %s\n",
state, f);
int i;
Expand Down
4 changes: 4 additions & 0 deletions src/base/gcewing/sg/BlockPos.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ public BlockPos offset(EnumFacing dir) {
return new BlockPos(x + v.getX(), y + v.getY(), z + v.getZ());
}

public boolean equals(BlockPos other) {
return this.x == other.x && this.y == other.y && this.z == other.z;
}

@Override
public String toString() {
return String.format("(%s,%s,%s)", x, y, z);
Expand Down
3 changes: 1 addition & 2 deletions src/mod/gcewing/sg/DHDBlock.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public boolean isOpaqueCube() {
@Override
public void onBlockAdded(World world, BlockPos pos, IBlockState state) {
if (SGBaseBlock.debugMerge)
System.out.printf("DHDBlock.onBlockAdded: at %d\n", pos);
System.out.printf("DHDBlock.onBlockAdded: at %s\n", pos);
checkForLink(world, pos);
}

Expand All @@ -75,7 +75,6 @@ public void onBlockPlacedBy(World world, BlockPos pos, IBlockState state, Entity
}

@Override
// public boolean canHarvestBlock(IBlockAccess world, BlockPos pos, EntityPlayer player) {
public boolean canHarvestBlock(IBlockState state, EntityPlayer player) {
return true;
}
Expand Down
11 changes: 4 additions & 7 deletions src/mod/gcewing/sg/DHDScreen.java
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,8 @@ public void updateScreen() {
}

@Override
public void mousePressed(int x, int y, int mouseButton) {
System.out.printf("DHDScreen.mousePressed: %d, %d, %d\n", x, y, mouseButton);
protected void mousePressed(int x, int y, int mouseButton) {
//System.out.printf("DHDScreen.mousePressed: %d, %d, %d\n", x, y, mouseButton);
if (mouseButton == 0) {
int i = findDHDButton(x, y);
if (i >= 0) {
Expand Down Expand Up @@ -140,12 +140,12 @@ int findDHDButton(int mx, int my) {
i0 = 27; nb = 11;
}
int i = i0 + (int)Math.floor(a * nb / 360);
System.out.printf("DHDScreen.findDHDButton: i = %d\n", i);
//System.out.printf("DHDScreen.findDHDButton: i = %d\n", i);
return i;
}

void dhdButtonPressed(int i) {
System.out.printf("DHDScreen.dhdButtonPressed: %d\n", i);
//System.out.printf("DHDScreen.dhdButtonPressed: %d\n", i);
buttonSound();
if (i == 0)
orangeButtonPressed(false);
Expand Down Expand Up @@ -181,9 +181,7 @@ else if (key == Keyboard.KEY_RETURN || key == Keyboard.KEY_NUMPADENTER)

void orangeButtonPressed(boolean connectOnly) {
SGBaseTE te = getStargateTE();
System.out.printf("DHDScreen.orangeButtonPressed: connectOnly = %s, te = %s\n", connectOnly, te);
if (te != null) {
System.out.printf("DHDScreen.orangeButtonPressed: state = %s\n", te.state);
if (te.state == SGState.Idle)
sendConnectOrDisconnect(te, getEnteredAddress());
else if (!connectOnly)
Expand All @@ -192,7 +190,6 @@ else if (!connectOnly)
}

void sendConnectOrDisconnect(SGBaseTE te, String address) {
System.out.printf("DHDScreen.sendConnectOrDisconnect: %s %s\n", te, address);
SGChannel.sendConnectOrDisconnectToServer(te, address);
closeAfterDelay(10);
}
Expand Down
11 changes: 8 additions & 3 deletions src/mod/gcewing/sg/IrisEntity.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@

public class IrisEntity extends BaseEntity implements IEntityAdditionalSpawnData {

public static boolean debugIrisEntity = false;

BlockPos blockPos;

public IrisEntity(World world) {
Expand All @@ -48,7 +50,8 @@ public IrisEntity(SGBaseTE te) {
}

void init(BlockPos pos, AxisAlignedBB box) {
//System.out.printf("IrisEntity.init: %s at %s box %s\n", this, pos, box);
if (debugIrisEntity)
System.out.printf("IrisEntity.init: %s at %s box %s\n", this, pos, box);
this.blockPos = pos;
setPosition(box.minX, box.minY, box.minZ);
setBoundingBox(box);
Expand Down Expand Up @@ -93,7 +96,8 @@ public boolean canBePushed() {

@Override
public void readEntityFromNBT(NBTTagCompound nbt) {
//System.out.printf("IrisEntity.readEntityFromNBT\n");
if (debugIrisEntity)
System.out.printf("IrisEntity.readEntityFromNBT: %s\n", nbt);
int blockX = nbt.getInteger("blockX");
int blockY = nbt.getInteger("blockY");
int blockZ = nbt.getInteger("blockZ");
Expand All @@ -110,7 +114,6 @@ public void readEntityFromNBT(NBTTagCompound nbt) {

@Override
public void writeEntityToNBT(NBTTagCompound nbt) {
//System.out.printf("IrisEntity.writeEntityToNBT\n");
nbt.setInteger("blockX", blockPos.getX());
nbt.setInteger("blockY", blockPos.getY());
nbt.setInteger("blockZ", blockPos.getZ());
Expand All @@ -121,6 +124,8 @@ public void writeEntityToNBT(NBTTagCompound nbt) {
nbt.setDouble("maxX", box.maxX);
nbt.setDouble("maxY", box.maxY);
nbt.setDouble("maxZ", box.maxZ);
if (debugIrisEntity)
System.out.printf("IrisEntity.writeEntityToNBT: %s\n", nbt);
}

@Override
Expand Down
4 changes: 2 additions & 2 deletions src/mod/gcewing/sg/SGBaseBlock.java
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ public boolean isMerged(IBlockAccess world, BlockPos pos) {
@Override
public void onBlockAdded(World world, BlockPos pos, IBlockState state) {
if (SGBaseBlock.debugMerge)
System.out.printf("SGBaseBlock.onBlockAdded: at %d\n", pos);
System.out.printf("SGBaseBlock.onBlockAdded: at %s\n", pos);
checkForMerge(world, pos);
}

Expand Down Expand Up @@ -252,7 +252,7 @@ void unmergeRing(World world, BlockPos pos) {

void unmergeRingBlock(World world, BlockPos pos, BlockPos ringPos) {
//System.out.printf("SGBaseBlock.unmergeRingBlock at (%d,%d,%d)\n", xr, yr, zr);
Block block = getWorldBlock(world, pos);
Block block = getWorldBlock(world, ringPos);
if (debugMerge)
System.out.printf("SGBaseBlock.unmergeRingBlock: found %s at %s\n", block, ringPos);
if (block instanceof SGRingBlock) {
Expand Down
Loading

0 comments on commit b6eba61

Please sign in to comment.