Skip to content

Commit

Permalink
Finished updating to 1.11.2
Browse files Browse the repository at this point in the history
  • Loading branch information
TheTurkeyDev committed Jun 18, 2017
1 parent 6f4a78c commit b167424
Show file tree
Hide file tree
Showing 4 changed files with 156 additions and 125 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@ public void onGameOverlayRender(RenderGameOverlayEvent event) {

InventoryPlayer inv = player.inventory;

for (int slot = 0; slot < inv.mainInventory.length; slot++) {
for (int slot = 0; slot < inv.mainInventory.size(); slot++) {
ItemStack is = inv.getStackInSlot(slot);
if (is != null && is.isItemEqual(source)) quantity += is.stackSize;
if (is != null && is.isItemEqual(source)) quantity += is.getCount();
}

this.lastExchangeSourceCount = quantity;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,101 +26,126 @@ public class RenderOverlayHandler {
@SubscribeEvent
public void RenderWorldLastEvent(RenderWorldLastEvent event) {

EntityPlayerSP player = Minecraft.getMinecraft().player;
World world = player.getEntityWorld();
ItemStack stack = player.getHeldItemMainhand();
Minecraft mc = Minecraft.getMinecraft();
float partialTicks = event.getPartialTicks();

RayTraceResult mouseOver = mc.objectMouseOver;

if (stack != null && stack.getItem() instanceof ItemExchangerBase && stack.getTagCompound() != null && mouseOver != null && mouseOver.getBlockPos() != null && mouseOver.sideHit != null) {
List<BlockPos> blocks = ItemExchangerBase.getBlocksToExchange(stack, mouseOver.getBlockPos(), world, mc.objectMouseOver.sideHit);

Tessellator tessellator = Tessellator.getInstance();
VertexBuffer buffer = tessellator.getBuffer();

double offsetX = player.prevPosX + (player.posX - player.prevPosX) * (double) partialTicks;
double offsetY = player.prevPosY + (player.posY - player.prevPosY) * (double) partialTicks;
double offsetZ = player.prevPosZ + (player.posZ - player.prevPosZ) * (double) partialTicks;

GlStateManager.enableBlend();
GlStateManager.tryBlendFuncSeparate(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA, GlStateManager.SourceFactor.ONE, GlStateManager.DestFactor.ZERO);
GlStateManager.color(1F, 1F, 1F, 1F);
GlStateManager.glLineWidth(3.0F);
GlStateManager.disableTexture2D();

for (BlockPos block : blocks) {
if (world.isAirBlock(block)) {
continue;
}

double renderX = block.getX() - offsetX;
double renderY = block.getY() - offsetY;
double renderZ = block.getZ() - offsetZ;

AxisAlignedBB boundingBox = new AxisAlignedBB(renderX, renderY, renderZ, renderX + 1, renderY + 1, renderZ + 1).expand(0.001, 0.001, 0.001);

float colourR = 1F;
float colourG = 1F;
float colourB = 1F;
float colourA = 1F;

if (Block.getBlockFromName(stack.getTagCompound().getString("BlockName")) == null) {
colourR = 1F;
colourG = 0.1F;
colourB = 0.1F;
colourA = 1F;
}

if (player.isSneaking()) {
colourR = 0.1F;
colourG = 1F;
colourB = 0.1F;
colourA = 1F;
}

if (!world.getBlockState(block.offset(mc.objectMouseOver.sideHit)).getBlock().isReplaceable(world, block.offset(mc.objectMouseOver.sideHit))) {
GlStateManager.disableDepth();
colourR = 0.2F;
colourG = 0.2F;
colourB = 0.2F;
colourA = 0.2F;
}

buffer.begin(3, DefaultVertexFormats.POSITION_COLOR);
buffer.pos(boundingBox.minX, boundingBox.minY, boundingBox.minZ).color(colourR, colourG, colourB, colourA).endVertex();
buffer.pos(boundingBox.maxX, boundingBox.minY, boundingBox.minZ).color(colourR, colourG, colourB, colourA).endVertex();
buffer.pos(boundingBox.maxX, boundingBox.minY, boundingBox.maxZ).color(colourR, colourG, colourB, colourA).endVertex();
buffer.pos(boundingBox.minX, boundingBox.minY, boundingBox.maxZ).color(colourR, colourG, colourB, colourA).endVertex();
buffer.pos(boundingBox.minX, boundingBox.minY, boundingBox.minZ).color(colourR, colourG, colourB, colourA).endVertex();
tessellator.draw();
buffer.begin(3, DefaultVertexFormats.POSITION_COLOR);
buffer.pos(boundingBox.minX, boundingBox.maxY, boundingBox.minZ).color(colourR, colourG, colourB, colourA).endVertex();
buffer.pos(boundingBox.maxX, boundingBox.maxY, boundingBox.minZ).color(colourR, colourG, colourB, colourA).endVertex();
buffer.pos(boundingBox.maxX, boundingBox.maxY, boundingBox.maxZ).color(colourR, colourG, colourB, colourA).endVertex();
buffer.pos(boundingBox.minX, boundingBox.maxY, boundingBox.maxZ).color(colourR, colourG, colourB, colourA).endVertex();
buffer.pos(boundingBox.minX, boundingBox.maxY, boundingBox.minZ).color(colourR, colourG, colourB, colourA).endVertex();
tessellator.draw();
buffer.begin(1, DefaultVertexFormats.POSITION_COLOR);
buffer.pos(boundingBox.minX, boundingBox.minY, boundingBox.minZ).color(colourR, colourG, colourB, colourA).endVertex();
buffer.pos(boundingBox.minX, boundingBox.maxY, boundingBox.minZ).color(colourR, colourG, colourB, colourA).endVertex();
buffer.pos(boundingBox.maxX, boundingBox.minY, boundingBox.minZ).color(colourR, colourG, colourB, colourA).endVertex();
buffer.pos(boundingBox.maxX, boundingBox.maxY, boundingBox.minZ).color(colourR, colourG, colourB, colourA).endVertex();
buffer.pos(boundingBox.maxX, boundingBox.minY, boundingBox.maxZ).color(colourR, colourG, colourB, colourA).endVertex();
buffer.pos(boundingBox.maxX, boundingBox.maxY, boundingBox.maxZ).color(colourR, colourG, colourB, colourA).endVertex();
buffer.pos(boundingBox.minX, boundingBox.minY, boundingBox.maxZ).color(colourR, colourG, colourB, colourA).endVertex();
buffer.pos(boundingBox.minX, boundingBox.maxY, boundingBox.maxZ).color(colourR, colourG, colourB, colourA).endVertex();
tessellator.draw();

if (!world.getBlockState(block.offset(mc.objectMouseOver.sideHit)).getBlock().isReplaceable(world, block.offset(mc.objectMouseOver.sideHit))) {
GlStateManager.enableDepth();
}
}

GlStateManager.enableTexture2D();
GlStateManager.disableBlend();
}
EntityPlayerSP player = Minecraft.getMinecraft().player;
World world = player.getEntityWorld();
ItemStack stack = player.getHeldItemMainhand();
Minecraft mc = Minecraft.getMinecraft();
float partialTicks = event.getPartialTicks();

RayTraceResult mouseOver = mc.objectMouseOver;

if (stack != null && stack.getItem() instanceof ItemExchangerBase && stack.getTagCompound() != null
&& mouseOver != null && mouseOver.getBlockPos() != null && mouseOver.sideHit != null) {
List<BlockPos> blocks = ItemExchangerBase.getBlocksToExchange(stack, mouseOver.getBlockPos(), world,
mc.objectMouseOver.sideHit);

Tessellator tessellator = Tessellator.getInstance();
VertexBuffer buffer = tessellator.getBuffer();

double offsetX = player.prevPosX + (player.posX - player.prevPosX) * (double) partialTicks;
double offsetY = player.prevPosY + (player.posY - player.prevPosY) * (double) partialTicks;
double offsetZ = player.prevPosZ + (player.posZ - player.prevPosZ) * (double) partialTicks;

GlStateManager.enableBlend();
GlStateManager.tryBlendFuncSeparate(GlStateManager.SourceFactor.SRC_ALPHA,
GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA, GlStateManager.SourceFactor.ONE,
GlStateManager.DestFactor.ZERO);
GlStateManager.color(1F, 1F, 1F, 1F);
GlStateManager.glLineWidth(3.0F);
GlStateManager.disableTexture2D();

for (BlockPos block : blocks) {
if (world.isAirBlock(block)) {
continue;
}

double renderX = block.getX() - offsetX;
double renderY = block.getY() - offsetY;
double renderZ = block.getZ() - offsetZ;

AxisAlignedBB boundingBox = new AxisAlignedBB(renderX, renderY, renderZ, renderX + 1, renderY + 1,
renderZ + 1).expand(0.001, 0.001, 0.001);

float colourR = 1F;
float colourG = 1F;
float colourB = 1F;
float colourA = 1F;

if (Block.getBlockFromName(stack.getTagCompound().getString("BlockName")) == null) {
colourR = 1F;
colourG = 0.1F;
colourB = 0.1F;
colourA = 1F;
}

if (player.isSneaking()) {
colourR = 0.1F;
colourG = 1F;
colourB = 0.1F;
colourA = 1F;
}

if (!world.getBlockState(block.offset(mc.objectMouseOver.sideHit)).getBlock().isReplaceable(world,
block.offset(mc.objectMouseOver.sideHit))) {
GlStateManager.disableDepth();
colourR = 0.2F;
colourG = 0.2F;
colourB = 0.2F;
colourA = 0.2F;
}

buffer.begin(3, DefaultVertexFormats.POSITION_COLOR);
buffer.pos(boundingBox.minX, boundingBox.minY, boundingBox.minZ)
.color(colourR, colourG, colourB, colourA).endVertex();
buffer.pos(boundingBox.maxX, boundingBox.minY, boundingBox.minZ)
.color(colourR, colourG, colourB, colourA).endVertex();
buffer.pos(boundingBox.maxX, boundingBox.minY, boundingBox.maxZ)
.color(colourR, colourG, colourB, colourA).endVertex();
buffer.pos(boundingBox.minX, boundingBox.minY, boundingBox.maxZ)
.color(colourR, colourG, colourB, colourA).endVertex();
buffer.pos(boundingBox.minX, boundingBox.minY, boundingBox.minZ)
.color(colourR, colourG, colourB, colourA).endVertex();
tessellator.draw();
buffer.begin(3, DefaultVertexFormats.POSITION_COLOR);
buffer.pos(boundingBox.minX, boundingBox.maxY, boundingBox.minZ)
.color(colourR, colourG, colourB, colourA).endVertex();
buffer.pos(boundingBox.maxX, boundingBox.maxY, boundingBox.minZ)
.color(colourR, colourG, colourB, colourA).endVertex();
buffer.pos(boundingBox.maxX, boundingBox.maxY, boundingBox.maxZ)
.color(colourR, colourG, colourB, colourA).endVertex();
buffer.pos(boundingBox.minX, boundingBox.maxY, boundingBox.maxZ)
.color(colourR, colourG, colourB, colourA).endVertex();
buffer.pos(boundingBox.minX, boundingBox.maxY, boundingBox.minZ)
.color(colourR, colourG, colourB, colourA).endVertex();
tessellator.draw();
buffer.begin(1, DefaultVertexFormats.POSITION_COLOR);
buffer.pos(boundingBox.minX, boundingBox.minY, boundingBox.minZ)
.color(colourR, colourG, colourB, colourA).endVertex();
buffer.pos(boundingBox.minX, boundingBox.maxY, boundingBox.minZ)
.color(colourR, colourG, colourB, colourA).endVertex();
buffer.pos(boundingBox.maxX, boundingBox.minY, boundingBox.minZ)
.color(colourR, colourG, colourB, colourA).endVertex();
buffer.pos(boundingBox.maxX, boundingBox.maxY, boundingBox.minZ)
.color(colourR, colourG, colourB, colourA).endVertex();
buffer.pos(boundingBox.maxX, boundingBox.minY, boundingBox.maxZ)
.color(colourR, colourG, colourB, colourA).endVertex();
buffer.pos(boundingBox.maxX, boundingBox.maxY, boundingBox.maxZ)
.color(colourR, colourG, colourB, colourA).endVertex();
buffer.pos(boundingBox.minX, boundingBox.minY, boundingBox.maxZ)
.color(colourR, colourG, colourB, colourA).endVertex();
buffer.pos(boundingBox.minX, boundingBox.maxY, boundingBox.maxZ)
.color(colourR, colourG, colourB, colourA).endVertex();
tessellator.draw();

if (!world.getBlockState(block.offset(mc.objectMouseOver.sideHit)).getBlock().isReplaceable(world,
block.offset(mc.objectMouseOver.sideHit))) {
GlStateManager.enableDepth();
}
}

GlStateManager.enableTexture2D();
GlStateManager.disableBlend();
}

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,12 +98,13 @@ public void addInformation(ItemStack stack, EntityPlayer player, List<String> to
tooltip.add("Use the mode key (default 'COMMA') to switch modes.");
}

public EnumActionResult onItemUse(ItemStack stack, EntityPlayer player, World world, BlockPos pos, EnumHand hand,
EnumFacing facing, float hitX, float hitY, float hitZ) {
public EnumActionResult onItemUse(EntityPlayer player, World world, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ)
{
if (world.isRemote) {
return EnumActionResult.PASS;
}

ItemStack stack = player.getHeldItem(hand);
IBlockState state = world.getBlockState(pos);
Block block = state.getBlock();

Expand Down Expand Up @@ -359,7 +360,7 @@ public static boolean exchangeBlocks(ItemStack stack, EntityPlayer player, World
return false;
}

if (slot >= 0 && player.inventory.mainInventory[slot].stackSize > 0) {
if (slot >= 0 && player.inventory.mainInventory.get(slot).getCount() > 0) {
Block oldBlock = world.getBlockState(exchangePos).getBlock();
int oldMeta = oldBlock.getMetaFromState(world.getBlockState(exchangePos));

Expand Down Expand Up @@ -406,8 +407,10 @@ private static boolean consumeBlockInInventory(EntityPlayer player, Block block,
if (slot < 0) {
return false;
} else {
if (--inv.mainInventory[slot].stackSize <= 0) {
inv.mainInventory[slot] = null;
ItemStack stack = inv.mainInventory.get(slot);
stack.shrink(1);
if (stack.getCount() <= 0) {
inv.mainInventory.set(slot, ItemStack.EMPTY);
}

}
Expand All @@ -417,9 +420,9 @@ private static boolean consumeBlockInInventory(EntityPlayer player, Block block,
}

private static int findItemInInventory(InventoryPlayer inv, Item item, int meta) {
for (int i = 0; i < inv.mainInventory.length; i++) {
if (inv.mainInventory != null && inv.mainInventory[i].getItem() == item
&& inv.mainInventory[i].getItemDamage() == meta) {
for (int i = 0; i < inv.mainInventory.size(); i++) {
if (inv.mainInventory != null && inv.mainInventory.get(i).getItem() == item
&& inv.mainInventory.get(i).getItemDamage() == meta) {
return i;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,48 +16,51 @@

public class ItemTuberousExchanger extends ItemExchangerBase {

public ItemTuberousExchanger(){
setRegistryName(Exchangers.MODID + ":tuberous_exchanger");
setUnlocalizedName(Exchangers.MODID + ".tuberous_exchanger");
setMaxStackSize(1);
setMaxDamage(1);
setCreativeTab(Exchangers.exchangersCreativeTab);
public ItemTuberousExchanger() {
setRegistryName(Exchangers.MODID + ":tuberous_exchanger");
setUnlocalizedName(Exchangers.MODID + ".tuberous_exchanger");
setMaxStackSize(1);
setMaxDamage(1);
setCreativeTab(Exchangers.exchangersCreativeTab);
}

@SideOnly(Side.CLIENT)
public void initModel() {
ModelLoader.setCustomModelResourceLocation(this, 0, new ModelResourceLocation(getRegistryName(), "inventory"));
ModelLoader.setCustomModelResourceLocation(this, 0, new ModelResourceLocation(getRegistryName(), "inventory"));
}

@Override
public void addInformation(ItemStack stack, EntityPlayer player, List<String> tooltip, boolean bool) {
super.addInformation(stack, player, tooltip, bool);
super.addInformation(stack, player, tooltip, bool);

tooltip.add(ChatFormatting.RED + "Clever! But not exchangeable.");
tooltip.add(ChatFormatting.RED + "Clever! But not exchangeable.");
}

@Override
public EnumActionResult onItemUse(ItemStack stack, EntityPlayer player, World world, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
return killPlayer(player, stack)? EnumActionResult.SUCCESS : EnumActionResult.FAIL;
public EnumActionResult onItemUse(EntityPlayer player, World worldIn, BlockPos pos, EnumHand hand,
EnumFacing facing, float hitX, float hitY, float hitZ) {
ItemStack stack = player.getHeldItem(hand);
return killPlayer(player, stack) ? EnumActionResult.SUCCESS : EnumActionResult.FAIL;
}

@Override
public ActionResult<ItemStack> onItemRightClick(World world, EntityPlayer player, EnumHand hand) {
boolean result = killPlayer(player, player.getHeldItem(hand));
return ActionResult.newResult(result? EnumActionResult.SUCCESS : EnumActionResult.FAIL, player.getHeldItem(hand));
boolean result = killPlayer(player, player.getHeldItem(hand));
return ActionResult.newResult(result ? EnumActionResult.SUCCESS : EnumActionResult.FAIL,
player.getHeldItem(hand));
}

private static boolean killPlayer(EntityPlayer player, ItemStack stack) {

if(player instanceof EntityPlayer) {
stack.setCount(0);
player.attackEntityFrom(new EntityDamageSource("exchangerpotato", player), 100000.0F);
player.world.createExplosion(player, player.posX, player.posY, player.posZ, 1.0F, false);
if (player instanceof EntityPlayer) {
stack.setCount(0);
player.attackEntityFrom(new EntityDamageSource("exchangerpotato", player), 100000.0F);
player.world.createExplosion(player, player.posX, player.posY, player.posZ, 1.0F, false);

return true;
}
return true;
}

return false;
return false;

}

Expand Down

0 comments on commit b167424

Please sign in to comment.