use of com.codetaylor.mc.artisanworktables.modules.worktables.tile.spi.TileEntityBase in project artisan-worktables by codetaylor.
the class BlockBase method onBlockActivated.
@Override
public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
if (worldIn.isRemote) {
GuiElementTabs.RECALCULATE_TAB_OFFSETS = true;
return true;
}
TileEntity tileEntity = worldIn.getTileEntity(pos);
if (tileEntity instanceof TileEntityBase) {
FluidTank tank = ((TileEntityBase) tileEntity).getTank();
if (FluidHelper.drainWaterFromBottle(playerIn, tank) || FluidHelper.drainWaterIntoBottle(playerIn, tank) || FluidUtil.interactWithFluidHandler(playerIn, hand, tank)) {
return true;
}
playerIn.openGui(ModuleWorktables.MOD_INSTANCE, 1, worldIn, pos.getX(), pos.getY(), pos.getZ());
return true;
}
return super.onBlockActivated(worldIn, pos, state, playerIn, hand, facing, hitX, hitY, hitZ);
}
use of com.codetaylor.mc.artisanworktables.modules.worktables.tile.spi.TileEntityBase in project artisan-worktables by codetaylor.
the class GuiElementTabs method mouseClicked.
@Override
public void mouseClicked(int mouseX, int mouseY, int mouseButton) {
if (mouseButton != 0) {
return;
}
List<TileEntityBase> actualJoinedTables = this.worktable.getJoinedTables(new ArrayList<>(), Minecraft.getMinecraft().player);
List<TileEntityBase> joinedTables = this.getJoinedTableOffsetView(actualJoinedTables, GUI_TAB_OFFSET.getOffset(), this.worktable.getMaximumDisplayedTabCount());
int yMin = this.elementYModifiedGet();
int yMax = yMin + TAB_HEIGHT;
for (int i = 0; i < joinedTables.size(); i++) {
int xMin = this.elementXModifiedGet() + TAB_ITEM_HORIZONTAL_OFFSET + (TAB_WIDTH + TAB_SPACING) * i;
int xMax = xMin + TAB_WIDTH;
if (mouseX <= xMax && mouseX >= xMin && mouseY <= yMax && mouseY >= yMin) {
TileEntityBase table = joinedTables.get(i);
BlockPos pos = table.getPos();
ModuleWorktables.PACKET_SERVICE.sendToServer(new SPacketWorktableTab(pos));
Minecraft.getMinecraft().getSoundHandler().playSound(PositionedSoundRecord.getMasterRecord(SoundEvents.UI_BUTTON_CLICK, 1));
}
}
int maximumDisplayedTabCount = this.worktable.getMaximumDisplayedTabCount();
if (GUI_TAB_OFFSET.getOffset() > 0) {
// check for left button click
int xMin = this.elementXModifiedGet() + TAB_LEFT_OFFSET + TAB_ITEM_HORIZONTAL_OFFSET - 18;
int xMax = xMin + 8;
if (mouseX <= xMax && mouseX >= xMin && mouseY <= yMax && mouseY >= yMin) {
int tabOffset = GUI_TAB_OFFSET.getOffset() - maximumDisplayedTabCount;
GUI_TAB_OFFSET.setOffset(Math.max(0, tabOffset));
Minecraft.getMinecraft().getSoundHandler().playSound(PositionedSoundRecord.getMasterRecord(SoundEvents.UI_BUTTON_CLICK, 1));
}
}
if (GUI_TAB_OFFSET.getOffset() + maximumDisplayedTabCount < actualJoinedTables.size()) {
// check for right button click
int xMin = this.elementXModifiedGet() + this.elementWidthModifiedGet() - 12;
int xMax = xMin + 8;
if (mouseX <= xMax && mouseX >= xMin && mouseY <= yMax && mouseY >= yMin) {
GUI_TAB_OFFSET.setOffset(Math.min(actualJoinedTables.size() - maximumDisplayedTabCount, GUI_TAB_OFFSET.getOffset() + maximumDisplayedTabCount));
Minecraft.getMinecraft().getSoundHandler().playSound(PositionedSoundRecord.getMasterRecord(SoundEvents.UI_BUTTON_CLICK, 1));
}
}
}
use of com.codetaylor.mc.artisanworktables.modules.worktables.tile.spi.TileEntityBase in project artisan-worktables by codetaylor.
the class GuiElementTabs method drawBackgroundLayer.
@Override
public void drawBackgroundLayer(float partialTicks, int mouseX, int mouseY) {
GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
int x = this.elementXModifiedGet();
int y = this.elementYModifiedGet();
int tabX = x + TAB_LEFT_OFFSET;
int tabY = y;
List<TileEntityBase> actualJoinedTables = this.worktable.getJoinedTables(new ArrayList<>(), Minecraft.getMinecraft().player);
List<TileEntityBase> joinedTables = this.getJoinedTableOffsetView(actualJoinedTables, GUI_TAB_OFFSET.getOffset(), this.worktable.getMaximumDisplayedTabCount());
this.textureBind(ReferenceTexture.RESOURCE_LOCATION_GUI_ELEMENTS);
if (GUI_TAB_OFFSET.getOffset() > 0) {
// draw left button
Gui.drawModalRectWithCustomSizedTexture(this.elementXModifiedGet() + TAB_LEFT_OFFSET + TAB_ITEM_HORIZONTAL_OFFSET - 18, tabY, TAB_WIDTH, this.worktable.getWorktableGuiTabTextureYOffset() * TAB_HEIGHT, 8, TAB_HEIGHT, ReferenceTexture.TEXTURE_GUI_ELEMENTS_WIDTH, ReferenceTexture.TEXTURE_GUI_ELEMENTS_HEIGHT);
}
int maximumDisplayedTabCount = this.worktable.getMaximumDisplayedTabCount();
if (GUI_TAB_OFFSET.getOffset() + maximumDisplayedTabCount < actualJoinedTables.size()) {
// draw right button
Gui.drawModalRectWithCustomSizedTexture(this.elementXModifiedGet() + this.elementWidthModifiedGet() - 12, tabY, TAB_WIDTH + 8, this.worktable.getWorktableGuiTabTextureYOffset() * TAB_HEIGHT, 8, TAB_HEIGHT, ReferenceTexture.TEXTURE_GUI_ELEMENTS_WIDTH, ReferenceTexture.TEXTURE_GUI_ELEMENTS_HEIGHT);
}
for (TileEntityBase joinedTable : joinedTables) {
int textureY = joinedTable.getWorktableGuiTabTextureYOffset() * TAB_HEIGHT;
if (joinedTable == this.worktable) {
// this.drawTexturedModalRect(tabX, tabY + TAB_CURRENT_OFFSET, 0, textureY, TAB_WIDTH, TAB_HEIGHT);
Gui.drawModalRectWithCustomSizedTexture(tabX, tabY + TAB_CURRENT_OFFSET, 0, textureY, TAB_WIDTH, TAB_HEIGHT, ReferenceTexture.TEXTURE_GUI_ELEMENTS_WIDTH, ReferenceTexture.TEXTURE_GUI_ELEMENTS_HEIGHT);
} else {
// this.drawTexturedModalRect(tabX, tabY, 0, textureY, TAB_WIDTH, 21);
Gui.drawModalRectWithCustomSizedTexture(tabX, tabY, 0, textureY, TAB_WIDTH, TAB_HEIGHT, ReferenceTexture.TEXTURE_GUI_ELEMENTS_WIDTH, ReferenceTexture.TEXTURE_GUI_ELEMENTS_HEIGHT);
}
tabX += TAB_WIDTH + TAB_SPACING;
}
// draw tab icons
tabX = x + TAB_LEFT_OFFSET + TAB_ITEM_HORIZONTAL_OFFSET;
tabY = y + TAB_ITEM_VERTICAL_OFFSET;
RenderHelper.enableGUIStandardItemLighting();
for (TileEntityBase joinedTable : joinedTables) {
IBlockState blockState = joinedTable.getWorld().getBlockState(joinedTable.getPos());
blockState = blockState.getBlock().getActualState(blockState, this.worktable.getWorld(), joinedTable.getPos());
ItemStack itemStack = joinedTable.getItemStackForTabDisplay(blockState);
if (joinedTable == this.worktable) {
this.guiBase.getItemRender().renderItemAndEffectIntoGUI(itemStack, tabX, tabY + TAB_CURRENT_OFFSET);
} else {
this.guiBase.getItemRender().renderItemAndEffectIntoGUI(itemStack, tabX, tabY);
}
tabX += TAB_WIDTH + TAB_SPACING;
}
}
use of com.codetaylor.mc.artisanworktables.modules.worktables.tile.spi.TileEntityBase in project artisan-worktables by codetaylor.
the class GuiElementTabs method calculateInitialTabOffset.
/**
* Sets the initial tab offset when the gui is opened.
*
* @param worktableBase the worktable
* @param guiTabOffset the offset
*/
private void calculateInitialTabOffset(TileEntityBase worktableBase, GuiTabOffset guiTabOffset) {
int maximumDisplayedTabCount = worktableBase.getMaximumDisplayedTabCount();
guiTabOffset.setOffset(0);
List<TileEntityBase> actualJoinedTables = worktableBase.getJoinedTables(new ArrayList<>(), Minecraft.getMinecraft().player);
boolean tabInView = false;
while (!tabInView && !actualJoinedTables.isEmpty()) {
List<TileEntityBase> joinedTables = this.getJoinedTableOffsetView(actualJoinedTables, guiTabOffset.getOffset(), worktableBase.getMaximumDisplayedTabCount());
for (TileEntityBase joinedTable : joinedTables) {
if (joinedTable == worktableBase) {
tabInView = true;
break;
}
}
if (!tabInView) {
guiTabOffset.setOffset(Math.min(actualJoinedTables.size() - maximumDisplayedTabCount, guiTabOffset.getOffset() + maximumDisplayedTabCount));
}
}
}
use of com.codetaylor.mc.artisanworktables.modules.worktables.tile.spi.TileEntityBase in project artisan-worktables by codetaylor.
the class CPacketWorktableFluidUpdate method onMessage.
@Override
public IMessage onMessage(CPacketWorktableFluidUpdate message, MessageContext ctx, TileEntity tileEntity) {
if (tileEntity != null) {
TileEntityBase tileEntityBase = (TileEntityBase) tileEntity;
tileEntityBase.getTank().setFluid(message.fluidTank.getFluid());
// We don't force a container recipe update here because it's triggered
// when the tank's onContentsChanged() method is called.
}
return null;
}
Aggregations