Jump to content

Raycoms

Members
  • Posts

    383
  • Joined

  • Last visited

Everything posted by Raycoms

  1. I knew that it was because of clientSide only but I couldn't find which method I shouldn't have called. I created a new threat for the error to be able to view and analyze it better
  2. I got some ugly crash on world load I wasn't able to say why: log: http://pastebin.com/QzsgULS9 The method it seems to get problems: private void renderWorld(final float partialTicks, final long finishTimeNano) { GlStateManager.enableCull(); this.profiler.endStartSection("culling"); @NotNull final Frustum frustum = new Frustum(); final Entity entity = this.mc.getRenderViewEntity(); final double x = playerPositionOffset.xCoord; final double y = playerPositionOffset.yCoord; final double z = playerPositionOffset.zCoord; frustum.setPosition(x, y, z); GlStateManager.shadeModel(GL11.GL_SMOOTH); this.profiler.endStartSection("prepareterrain"); this.mc.getTextureManager().bindTexture(TextureMap.LOCATION_BLOCKS_TEXTURE); RenderHelper.disableStandardItemLighting(); this.profiler.endStartSection("terrain_setup"); setupTerrain(entity, partialTicks, frustum, this.frameCount, isInsideWorld(x, y, z)); this.frameCount++; this.profiler.endStartSection("updatechunks"); updateChunks(finishTimeNano / 2); this.profiler.endStartSection("terrain"); GlStateManager.matrixMode(GL11.GL_MODELVIEW); GlStateManager.pushMatrix(); GlStateManager.enableBlend(); GlStateManager.tryBlendFuncSeparate(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA, 1, 0); renderBlockLayer(BlockRenderLayer.SOLID, (double)partialTicks, PASS, entity); renderBlockLayer(BlockRenderLayer.CUTOUT_MIPPED, (double)partialTicks, PASS, entity); this.mc.getTextureManager().getTexture(TextureMap.LOCATION_BLOCKS_TEXTURE).setBlurMipmap(false, false); renderBlockLayer(BlockRenderLayer.CUTOUT, (double)partialTicks, PASS, entity); this.mc.getTextureManager().getTexture(TextureMap.LOCATION_BLOCKS_TEXTURE).restoreLastBlurMipmap(); GlStateManager.disableBlend(); GlStateManager.shadeModel(GL11.GL_FLAT); GlStateManager.alphaFunc(GL11.GL_GREATER, 0.1F); GlStateManager.matrixMode(GL11.GL_MODELVIEW); GlStateManager.popMatrix(); GlStateManager.pushMatrix(); this.profiler.endStartSection("entities"); RenderHelper.enableStandardItemLighting(); GlStateManager.enableBlend(); GlStateManager.tryBlendFuncSeparate(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA, 1, 0); renderEntities(entity, frustum, partialTicks); GlStateManager.disableBlend(); RenderHelper.disableStandardItemLighting(); disableLightmap(); GlStateManager.matrixMode(GL11.GL_MODELVIEW); GlStateManager.popMatrix(); GlStateManager.enableCull(); GlStateManager.alphaFunc(GL11.GL_GREATER, 0.1F); this.mc.getTextureManager().bindTexture(TextureMap.LOCATION_BLOCKS_TEXTURE); GlStateManager.shadeModel(GL11.GL_SMOOTH); GlStateManager.depthMask(false); GlStateManager.pushMatrix(); this.profiler.endStartSection("translucent"); GlStateManager.enableBlend(); GlStateManager.tryBlendFuncSeparate(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA, 1, 0); renderBlockLayer(BlockRenderLayer.TRANSLUCENT, (double)partialTicks, PASS, entity); GlStateManager.disableBlend(); GlStateManager.popMatrix(); GlStateManager.depthMask(true); GlStateManager.shadeModel(GL11.GL_FLAT); GlStateManager.enableCull(); } class: https://github.com/Minecolonies/minecolonies/blob/feature/%2357-Update-to-1.10.2/src/main/java/com/schematica/client/renderer/RenderSchematic.java
  3. Thanks alot. The crash I posted unfortunately still happens.
  4. How do I call existing sound events, where do I get them?
  5. Because I want to play it for the custom entity and not for the player but at the position. And I don't have the player at the moment in the code. But the problem here is that: new SoundEvent(new ResourceLocation("random.pop") Doesn't exist anymore at that location, actually I was not able to locate the sounds anymore.
  6. Fixed it with: this.getWorld().getMinecraftServer().getPlayerList().getPlayerList() But still didn't fix the sounds neither the other crash, anyone any idea?
  7. MinecraftServer doesn't seem to have this methods.
  8. Ahh. So how do I get the playerList on the server side? And how may I fix the sounds and the second crash?
  9. Sorry, first render method was the code of the wrong branch. https://github.com/Minecolonies/minecolonies/blob/feature/%2357-Update-to-1.10.2/src/main/java/com/schematica/client/renderer/RenderSchematic.java this is the 1.10 now.
  10. here is the colony class: https://github.com/Minecolonies/minecolonies/blob/feature/%2357-Update-to-1.10.2/src/main/java/com/minecolonies/colony/Colony.java and I searched all calls on the crashing line: Minecraft.getMinecraft().getIntegratedServer().getServer().getPlayerList().getPlayerList() the getMinecraft, the getIntegreatedServer, the getServer, the getPlayerList and again the getPlayerList, and none of them were marked as sideOnly(Side.Client)
  11. I searched the methods and couldn't find any SideOnly tag.
  12. Our users are getting some strange crashes on 1.10: This crash happens on world load it seems. http://pastebin.com/QzsgULS9 It seems to be a problem with the following method: private void renderWorld(final float partialTicks, final long finishTimeNano) { GlStateManager.enableCull(); this.profiler.endStartSection("culling"); @NotNull final Frustum frustum = new Frustum(); final Entity entity = this.mc.getRenderViewEntity(); final double x = playerPositionOffset.xCoord; final double y = playerPositionOffset.yCoord; final double z = playerPositionOffset.zCoord; frustum.setPosition(x, y, z); GlStateManager.shadeModel(GL11.GL_SMOOTH); this.profiler.endStartSection("prepareterrain"); this.mc.getTextureManager().bindTexture(TextureMap.LOCATION_BLOCKS_TEXTURE); RenderHelper.disableStandardItemLighting(); this.profiler.endStartSection("terrain_setup"); setupTerrain(entity, partialTicks, frustum, this.frameCount, isInsideWorld(x, y, z)); this.frameCount++; this.profiler.endStartSection("updatechunks"); updateChunks(finishTimeNano / 2); this.profiler.endStartSection("terrain"); GlStateManager.matrixMode(GL11.GL_MODELVIEW); GlStateManager.pushMatrix(); GlStateManager.enableBlend(); GlStateManager.tryBlendFuncSeparate(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA, 1, 0); renderBlockLayer(BlockRenderLayer.SOLID, (double)partialTicks, PASS, entity); renderBlockLayer(BlockRenderLayer.CUTOUT_MIPPED, (double)partialTicks, PASS, entity); this.mc.getTextureManager().getTexture(TextureMap.LOCATION_BLOCKS_TEXTURE).setBlurMipmap(false, false); renderBlockLayer(BlockRenderLayer.CUTOUT, (double)partialTicks, PASS, entity); this.mc.getTextureManager().getTexture(TextureMap.LOCATION_BLOCKS_TEXTURE).restoreLastBlurMipmap(); GlStateManager.disableBlend(); GlStateManager.shadeModel(GL11.GL_FLAT); GlStateManager.alphaFunc(GL11.GL_GREATER, 0.1F); GlStateManager.matrixMode(GL11.GL_MODELVIEW); GlStateManager.popMatrix(); GlStateManager.pushMatrix(); this.profiler.endStartSection("entities"); RenderHelper.enableStandardItemLighting(); GlStateManager.enableBlend(); GlStateManager.tryBlendFuncSeparate(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA, 1, 0); renderEntities(entity, frustum, partialTicks); GlStateManager.disableBlend(); RenderHelper.disableStandardItemLighting(); disableLightmap(); GlStateManager.matrixMode(GL11.GL_MODELVIEW); GlStateManager.popMatrix(); GlStateManager.enableCull(); GlStateManager.alphaFunc(GL11.GL_GREATER, 0.1F); this.mc.getTextureManager().bindTexture(TextureMap.LOCATION_BLOCKS_TEXTURE); GlStateManager.shadeModel(GL11.GL_SMOOTH); GlStateManager.depthMask(false); GlStateManager.pushMatrix(); this.profiler.endStartSection("translucent"); GlStateManager.enableBlend(); GlStateManager.tryBlendFuncSeparate(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA, 1, 0); renderBlockLayer(BlockRenderLayer.TRANSLUCENT, (double)partialTicks, PASS, entity); GlStateManager.disableBlend(); GlStateManager.popMatrix(); GlStateManager.depthMask(true); GlStateManager.shadeModel(GL11.GL_FLAT); GlStateManager.enableCull(); } Whole file: https://github.com/Minecolonies/minecolonies/blob/feature/%2357-Update-to-1.10.2/src/main/java/com/schematica/client/renderer/RenderSchematic.java
  13. Updating our mod to 1.10 currently. Fixing some minor bugs and will then push the newest version to curse. We're also always searching for active and experienced modders. Just fill out the application form on our forums.
  14. Okay, the following resolved the problem. Thanks. @Override public NBTTagCompound getUpdateTag() { return writeToNBT(new NBTTagCompound()); }
  15. I have to do something like this then? @Override public NBTTagCompound getUpdateTag() { return writeToNBT(super.getUpdateTag()); }
  16. We got a pretty strange problem. The readFromNBT method is called twice on start for every of our special tileEntities and is also called on blockUpdate. on the other side the writeToNBT isn't called again, which causes consistency problems since some of our variables haven't been set again. package com.minecolonies.tileentities; import com.minecolonies.colony.Colony; import com.minecolonies.colony.ColonyManager; import com.minecolonies.colony.ColonyView; import com.minecolonies.colony.buildings.AbstractBuilding; import com.minecolonies.colony.materials.MaterialSystem; import com.minecolonies.colony.permissions.Permissions; import com.sun.istack.internal.NotNull; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.network.NetworkManager; import net.minecraft.network.play.server.SPacketUpdateTileEntity; import net.minecraft.tileentity.TileEntityChest; import net.minecraft.util.math.BlockPos; /** * Class which handles the tileEntity of our colonyBuildings. */ public class TileEntityColonyBuilding extends TileEntityChest { private final static String TAG_COLONY = "colony"; private int colonyId = 0; private Colony colony; private AbstractBuilding building; /** * Empty standard constructor. */ public TileEntityColonyBuilding() { /** * Intentionally left empty. */ } @Override public SPacketUpdateTileEntity getUpdatePacket() { NBTTagCompound compound = new NBTTagCompound(); compound.setInteger(TAG_COLONY, colonyId); return new SPacketUpdateTileEntity(this.getPosition(), 0, compound); } @Override public void onDataPacket(NetworkManager net, SPacketUpdateTileEntity packet) { NBTTagCompound compound = packet.getNbtCompound(); colonyId = compound.getInteger(TAG_COLONY); } @Override public void update() { super.update(); if (!worldObj.isRemote) { if (colonyId == 0) { throw new IllegalStateException(String.format("TileEntityColonyBuilding at %s:[%d,%d,%d] has no colonyId", worldObj.getWorldInfo().getWorldName(), pos.getX(), pos.getY(), pos.getZ())); } } } @Override public void onChunkUnload() { if (building != null) { building.setTileEntity(null); } } /** * Returns the position of the tile entity * * @return Block Coordinates of the tile entity */ public BlockPos getPosition() { return pos; } /** * Synchronises colony references from the tile entity */ private void updateColonyReferences() { if (colony == null) { if (colonyId != 0) { colony = ColonyManager.getColony(colonyId); } else { throw new IllegalStateException(String.format("TileEntityColonyBuilding at %s:[%d,%d,%d] has no colonyId", worldObj.getWorldInfo().getWorldName(), pos.getX(), pos.getY(), pos.getZ())); } // else if (worldObj != null) // { // throw new IllegalStateException(String.format("TileEntityColonyBuilding at %s:[%d,%d,%d] has no colonyId", // worldObj.getWorldInfo().getWorldName(), xCoord, yCoord, zCoord)); // // colony = ColonyManager.getColony(worldObj, xCoord, yCoord, zCoord); // // if (colony != null) // { // colonyId = colony.getID(); // } // } } if (building == null && colony != null) { building = colony.getBuilding(getPosition()); if (building != null) { building.setTileEntity(this); } } } /** * Returns the colony ID * * @return ID of the colony */ public int getColonyId() { return colonyId; } /** * Returns the colony of the tile entity * * @return Colony of the tile entity */ public Colony getColony() { if (colony == null) { updateColonyReferences(); } return colony; } /** * Sets the colony of the tile entity * * @param c Colony to set in references */ public void setColony(Colony c) { colony = c; colonyId = c.getID(); markDirty(); } //todo something goes wrong on colony loading @Override public void readFromNBT(NBTTagCompound compound) { super.readFromNBT(compound); if (!compound.hasKey(TAG_COLONY)) { throw new IllegalStateException(String.format("TileEntityColonyBuilding at %s:[%d,%d,%d] missing COLONY tag.", worldObj.getWorldInfo().getWorldName(), pos.getX(), pos.getY(), pos.getZ())); } colonyId = compound.getInteger(TAG_COLONY); updateColonyReferences(); } /** * Returns the building associated with the tile entity * * @return {@link AbstractBuilding} associated with the tile entity */ public AbstractBuilding getBuilding() { if (building == null) { updateColonyReferences(); } return building; } /** * Sets the building associated with the tile entity * * @param b {@link AbstractBuilding} to associate with the tile entity */ public void setBuilding(AbstractBuilding b) { building = b; } @Override public NBTTagCompound writeToNBT(NBTTagCompound compound) { super.writeToNBT(compound); if (colonyId == 0) { throw new IllegalStateException(String.format("TileEntityColonyBuilding at %s:[%d,%d,%d] has no colonyId; %s colony reference.", worldObj.getWorldInfo().getWorldName(), pos.getX(), pos.getY(), pos.getZ(), colony == null ? "NO" : "valid")); } compound.setInteger(TAG_COLONY, colonyId); return compound; } /** * Returns the view of the building associated with the tile entity * * @return {@link AbstractBuilding.View} the tile entity is associated with */ public AbstractBuilding.View getBuildingView() { ColonyView c = ColonyManager.getColonyView(colonyId); return c != null ? c.getBuilding(getPosition()) : null; } @Override public boolean isUseableByPlayer(@NotNull EntityPlayer player) { return super.isUseableByPlayer(player) && this.hasAccessPermission(player); } /** * Checks if the player has permission to access the hut * * @param player Player to check permission of * @return True when player has access, or building doesn't exist, otherwise false. */ public boolean hasAccessPermission(EntityPlayer player)//TODO This is called every tick the GUI is open. Is that bad? { return building == null || building.getColony().getPermissions().hasPermission(player, Permissions.Action.ACCESS_HUTS); } //-----------------------------Material Handling-------------------------------- /** * Makes sure ItemStacks inside of the inventory aren't affected by changes to the returned stack. */ @Override public ItemStack getStackInSlot(int index) { ItemStack stack = super.getStackInSlot(index); if (stack == null) { return null; } return stack.copy(); } @Override public ItemStack decrStackSize(int index, int quantity) { ItemStack removed = super.decrStackSize(index, quantity); removeStackFromMaterialStore(removed); return removed; } @Override public ItemStack removeStackFromSlot(int index) { ItemStack removed = super.removeStackFromSlot(index); removeStackFromMaterialStore(removed); return removed; } @Override public void setInventorySlotContents(int index, ItemStack stack) { ItemStack previous = getStackInSlot(index); removeStackFromMaterialStore(previous); super.setInventorySlotContents(index, stack); addStackToMaterialStore(stack); } private void addStackToMaterialStore(ItemStack stack) { if (stack == null) { return; } if (MaterialSystem.isEnabled) { building.getMaterialStore().addMaterial(stack.getItem(), stack.stackSize); } } private void removeStackFromMaterialStore(ItemStack stack) { if (stack == null) { return; } if (MaterialSystem.isEnabled) { building.getMaterialStore().removeMaterial(stack.getItem(), stack.stackSize); } } }
  17. Okay, great thank you, that opaque cube method fixed it.
  18. It just renders it black and not with the texture, although he is loading the texture correctly, therefore, something is going wrong while setting it. And renders the onclosing blocks transparent.
  19. /src/main/resources/assets/minecolonies/textures/blocks/blockScarecrowPumpkin.png But I'm sure that is correct (If I remove a bit of this resource location he will throw an exception that he is unable to find) Constants.modId is "minecolonies"
  20. But both these methods are deprecated, so there should be something better to use? It still doesn't render the texture though.
  21. It's not animated yet but we're planning to.
  22. I'm currently porting to 1.10 and have a few questions. I had a TileEntity with a custom renderer. But a lot methods changed in the block. How do I set the following in 1.10: setBlockBounds((float) START_COLLISION, (float) BOTTOM_COLLISION, (float) START_COLLISION, (float) END_COLLISION, (float) HEIGHT_COLLISION, (float) END_COLLISION); @Override public boolean isFullCube(IBlockState state) { return false; } Currently the block doesn't move but it is planned for the future that's why we use the TileEntitySpecialRenderer. The entity is missing the texture and the bottom seems to be opaque. package com.minecolonies.client.render; import com.minecolonies.blocks.BlockHutField; import com.minecolonies.client.model.ModelScarecrowBoth; import com.minecolonies.lib.Constants; import com.minecolonies.tileentities.ScarecrowTileEntity; import net.minecraft.client.renderer.GlStateManager; import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer; import net.minecraft.util.EnumFacing; import net.minecraft.util.ResourceLocation; import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; import org.jetbrains.annotations.NotNull; /** * Class to render the scarecrow. */ @SideOnly(Side.CLIENT) public class TileEntityScarecrowRenderer extends TileEntitySpecialRenderer<ScarecrowTileEntity> { /** * Offset to the block middle. */ private static final double BLOCK_MIDDLE = 0.5; /** * Y-Offset in order to have the scarecrow over ground. */ private static final double YOFFSET = 1.5; /** * Which size the scarecrow should have ingame. */ private static final double SIZERATIO = .0625; /** * Rotate the model some degrees. */ private static final int ROTATION = 180; /** * Rotate it on the following x offset. */ private static final float XROTATIONOFFSET = 0.311F; /** * Rotate it on the following y offset. */ private static final float YROTATIONOFFSET = 0.0F; /** * Rotate it on the following z offset. */ private static final float ZROTATIONOFFSET = 2.845F; /** * Basic rotation to achieve a certain direction. */ private static final int BASIC_ROTATION = 90; /** * Rotate by amount to go east. */ private static final int ROTATE_EAST = 1; /** * Rotate by amount to go south. */ private static final int ROTATE_SOUTH = 2; /** * Rotate by amount to go west. */ private static final int ROTATE_WEST = 3; /** * The model of the scarecrow. */ @NotNull private final ModelScarecrowBoth model; /** * The public constructor for the renderer. */ public TileEntityScarecrowRenderer() { super(); this.model = new ModelScarecrowBoth(); } @Override public void renderTileEntityAt(@NotNull ScarecrowTileEntity te, double posX, double posY, double posZ, float partialTicks, int destroyStage) { //Store the transformation GlStateManager.pushMatrix(); //Set viewport to tile entity position to render it GlStateManager.translate(posX + BLOCK_MIDDLE, posY + YOFFSET, posZ + BLOCK_MIDDLE); this.bindTexture(getResourceLocation(te)); GlStateManager.rotate(ROTATION, XROTATIONOFFSET, YROTATIONOFFSET, ZROTATIONOFFSET); //In the case of worldLags tileEntities may sometimes disappear. if (getWorld().getBlockState(te.getPos()).getBlock() instanceof BlockHutField) { final EnumFacing facing = getWorld().getBlockState(te.getPos()).getValue(BlockHutField.FACING); switch (facing) { case EAST: GlStateManager.rotate((float) (BASIC_ROTATION * ROTATE_EAST), 0, 1, 0); break; case SOUTH: GlStateManager.rotate((float) (BASIC_ROTATION * ROTATE_SOUTH), 0, 1, 0); break; case WEST: GlStateManager.rotate((float) (BASIC_ROTATION * ROTATE_WEST), 0, 1, 0); break; default: //don't rotate at all. } } this.model.render((float) SIZERATIO); /* ============ Rendering Code stops here =========== */ //Restore the transformation, so other renderer's are not messed up. GlStateManager.popMatrix(); } /** * Returns the ResourceLocation of the scarecrow texture. * * @param tileEntity the tileEntity of the scarecrow. * @return the location. */ @NotNull private static ResourceLocation getResourceLocation(@NotNull ScarecrowTileEntity tileEntity) { String loc; if (tileEntity.getType() == ScarecrowTileEntity.ScareCrowType.PUMPKINHEAD) { loc = "textures/blocks/blockScarecrowPumpkin.pnh"; } else { loc = "textures/blocks/blockScarecrowNormal.png"; } return new ResourceLocation(Constants.MOD_ID + ":" + loc); } } package com.minecolonies.blocks; import com.minecolonies.MineColonies; import com.minecolonies.colony.Colony; import com.minecolonies.colony.ColonyManager; import com.minecolonies.creativetab.ModCreativeTabs; import com.minecolonies.inventory.InventoryField; import com.minecolonies.lib.Constants; import com.minecolonies.tileentities.ScarecrowTileEntity; import com.minecolonies.util.LanguageHandler; import net.minecraft.block.BlockContainer; import net.minecraft.block.BlockDirectional; import net.minecraft.block.material.Material; import net.minecraft.block.properties.IProperty; import net.minecraft.block.properties.PropertyDirection; import net.minecraft.block.state.BlockStateContainer; import net.minecraft.block.state.IBlockState; import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemBlock; import net.minecraft.item.ItemStack; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.BlockRenderLayer; import net.minecraft.util.EnumBlockRenderType; import net.minecraft.util.EnumFacing; import net.minecraft.util.EnumHand; import net.minecraft.util.math.AxisAlignedBB; import net.minecraft.util.math.BlockPos; import net.minecraft.world.IBlockAccess; import net.minecraft.world.World; import net.minecraftforge.fml.common.registry.GameRegistry; import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import static net.minecraft.util.EnumFacing.*; /** * The class handling the fieldBlocks, placement and activation. */ public class BlockHutField extends BlockContainer { /** * The position it faces. */ public static final PropertyDirection FACING = BlockDirectional.FACING; //public static final PropertyDirection FACING = PropertyDirection.create("FACING", Plane.HORIZONTAL); /** * Hardness of the block. */ private static final float HARDNESS = 10F; /** * Resistance of the block. */ private static final float RESISTANCE = 10F; /** * Start of the collision box at y. */ private static final double BOTTOM_COLLISION = 0.0; /** * Start of the collision box at x and z. */ private static final double START_COLLISION = 0.1; /** * End of the collision box. */ private static final double END_COLLISION = 0.9; /** * Height of the collision box. */ private static final double HEIGHT_COLLISION = 2.5; /** * Registry name for this block. */ private static final String REGISTRY_NAME = "blockHutField"; /** * Constructor called on block placement. */ BlockHutField() { super(Material.WOOD); initBlock(); } /** * Method called by constructor. * Sets basic details of the block. */ private void initBlock() { setRegistryName(REGISTRY_NAME); setUnlocalizedName(Constants.MOD_ID.toLowerCase() + "." + "blockHutField"); setCreativeTab(ModCreativeTabs.MINECOLONIES); //Blast resistance for creepers etc. makes them explosion proof. setResistance(RESISTANCE); //Hardness of 10 takes a long time to mine to not loose progress. setHardness(HARDNESS); this.setDefaultState(this.blockState.getBaseState().withProperty(FACING, NORTH)); GameRegistry.register(this); GameRegistry.register((new ItemBlock(this)).setRegistryName(this.getRegistryName())); } @Override public EnumBlockRenderType getRenderType(IBlockState state) { return EnumBlockRenderType.ENTITYBLOCK_ANIMATED; } @Override public int getMetaFromState(@NotNull IBlockState state) { return state.getValue(FACING).getIndex(); } @Override public boolean isFullCube(IBlockState state) { return false; } @Override public boolean isPassable(IBlockAccess worldIn, BlockPos pos) { return false; } @Deprecated public AxisAlignedBB getBoundingBox(IBlockState state, IBlockAccess source, BlockPos pos) { return new AxisAlignedBB((float) START_COLLISION, (float) BOTTOM_COLLISION, (float) START_COLLISION, (float) END_COLLISION, (float) HEIGHT_COLLISION, (float) END_COLLISION); } @NotNull @Override @SideOnly(Side.CLIENT) public BlockRenderLayer getBlockLayer() { return BlockRenderLayer.SOLID; } @Override public boolean onBlockActivated( World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, @Nullable ItemStack heldItem, EnumFacing side, float hitX, float hitY, float hitZ) { //If the world is server, open the inventory of the field. if (!worldIn.isRemote) { @Nullable final Colony colony = ColonyManager.getColony(worldIn, pos); if (colony != null) { playerIn.openGui(MineColonies.instance, 0, worldIn, pos.getX(), pos.getY(), pos.getZ()); return true; } } return false; } // ======================================================================= // ======================= Rendering & IBlockState ======================= // ======================================================================= @Override public IBlockState onBlockPlaced(World worldIn, BlockPos pos, EnumFacing facing, float hitX, float hitY, float hitZ, int meta, @Nullable EntityLivingBase placer) { @NotNull final EnumFacing enumFacing = (placer == null) ? NORTH : fromAngle(placer.rotationYaw); return this.getDefaultState().withProperty(FACING, enumFacing); } @Override public void onBlockPlacedBy(@NotNull World worldIn, @NotNull BlockPos pos, IBlockState state, EntityLivingBase placer, ItemStack stack) { //Only work on server side. if (worldIn.isRemote) { return; } if (placer instanceof EntityPlayer) { @Nullable final Colony colony = ColonyManager.getColony(worldIn, pos); if (colony != null) { @NotNull final InventoryField inventoryField = new InventoryField(LanguageHandler.getString("com.minecolonies.gui.inventory.scarecrow")); ((ScarecrowTileEntity) worldIn.getTileEntity(pos)).setInventoryField(inventoryField); colony.addNewField((ScarecrowTileEntity) worldIn.getTileEntity(pos), ((EntityPlayer) placer).inventory, pos, worldIn); } } } @NotNull @Override protected BlockStateContainer createBlockState() { return new BlockStateContainer(this, new IProperty[] {FACING}); } @Override public boolean hasTileEntity(final IBlockState state) { return true; } @NotNull @Override public TileEntity createNewTileEntity(World worldIn, int meta) { return new ScarecrowTileEntity(); } // ======================================================================= // ===================== END of Rendering & Meta-Data ==================== // ======================================================================= }
  23. About the Mod: Minecolonies allows you to create your very own colony in Minecraft! Put your citizens to work and ravage Minecraftia for its precious resources. Minecolonies is a revival of the original MineColony mod with a blessing from the former devs. The new name reflects our goal to make it an SMP experience where you can work with, or against, other player colonies. If you’re not ready to lead your own colony, just join your friends' colony and be his right-hand man. Main Features: - Fully functional Colony based around your town hall - Total freedom of placement of buildings with our build-tool. - Use the workers/combination of workers YOU want to use - No limit to the number of workers (except by proximity to the townhall) - Various different workers. - Fully customizable colony. http://files.enjin.com.s3.amazonaws.com/310371/modules/forum/attachments/2014-01-29_01.45.47_1390978405.png[/img] Announcements: The mod has been completely rewritten to 1.7 and recently ported to 1.8.9, 1.10.2 , 1.11.2 and 1.12.1. We also offer a great community and our own dedicated server. 1.8.9 Progress (Last Updated 06/09/2016): Workers: YouTube Channel: https://www.youtube.com/channel/UCqXDtO68H7ulwXW6tSlbmqA Official Website/Forums: http://www.minecolonies.com/welcome Click on "Official Website/Forums" above to view our official website. Be sure to register and participate in discussions, suggestions and more on the forums! Screenshots coming soon! Download: Licence: TERMS AND CONDITIONS Mod Packs: Thanks for reading, and enjoy the mod!
  24. Okay, we have an image class: package com.blockout.controls; import com.blockout.Pane; import com.blockout.PaneParams; import com.minecolonies.util.Log; import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.GlStateManager; import net.minecraft.util.ResourceLocation; import net.minecraft.util.Tuple; import javax.imageio.ImageIO; import javax.imageio.ImageReader; import javax.imageio.stream.ImageInputStream; import java.io.IOException; import java.util.Iterator; /** * Simple image element. */ public class Image extends Pane { public static final int MINECRAFT_DEFAULT_TEXTURE_MAP_SIZE = 256; protected ResourceLocation resourceLocation; protected int imageOffsetX = 0; protected int imageOffsetY = 0; protected int imageWidth = 0; protected int imageHeight = 0; protected int mapWidth = MINECRAFT_DEFAULT_TEXTURE_MAP_SIZE; protected int mapHeight = MINECRAFT_DEFAULT_TEXTURE_MAP_SIZE; /** * Default Constructor. */ public Image() { super(); } /** * Constructor used by the xml loader. * * @param params PaneParams loaded from the xml. */ public Image(PaneParams params) { super(params); String source = params.getStringAttribute("source", null); if (source != null) { resourceLocation = new ResourceLocation(source); loadMapDimensions(); } PaneParams.SizePair size = params.getSizePairAttribute("imageoffset", null, null); if (size != null) { imageOffsetX = size.getX(); imageOffsetY = size.getY(); } size = params.getSizePairAttribute("imagesize", null, null); if (size != null) { imageWidth = size.getX(); imageHeight = size.getY(); } } /** * Set the image. * * @param source String path. */ public void setImage(String source) { setImage(source, 0, 0, 0, 0); } /** * Set the image. * * @param source String path. * @param offsetX image x offset. * @param offsetY image y offset. * @param w image width. * @param h image height. */ public void setImage(String source, int offsetX, int offsetY, int w, int h) { setImage((source != null) ? new ResourceLocation(source) : null, offsetX, offsetY, w, h); } /** * Set the image. * * @param loc ResourceLocation for the image. */ public void setImage(ResourceLocation loc) { setImage(loc, 0, 0, 0, 0); } /** * Set the image. * * @param loc ResourceLocation for the image. * @param offsetX image x offset. * @param offsetY image y offset. * @param w image width. * @param h image height. */ public void setImage(ResourceLocation loc, int offsetX, int offsetY, int w, int h) { resourceLocation = loc; imageOffsetX = offsetX; imageOffsetY = offsetY; imageWidth = w; imageHeight = h; loadMapDimensions(); } /** * Draw this image on the GUI. * * @param mx Mouse x (relative to parent) * @param my Mouse y (relative to parent) */ @Override protected void drawSelf(int mx, int my) { // Some other texture must need to be ticked, I tried ticking the current one. // This fixes the problem, even if you put it after the draw call. So I guess I'll keep it. this.mc.getTextureManager().bindTexture(resourceLocation); GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F); //Draw drawModalRectWithCustomSizedTexture(x, y, imageOffsetX, imageOffsetY, imageWidth != 0 ? imageWidth : getWidth(), imageHeight != 0 ? imageHeight : getHeight(), mapWidth, mapHeight); } private void loadMapDimensions() { Tuple<Integer, Integer> dimensions = getImageDimensions(resourceLocation); mapWidth = dimensions.getFirst(); mapHeight = dimensions.getSecond(); } /** * Load and image from a {@link ResourceLocation} and return a {@link Tuple} containing its width and height. * * @param resourceLocation The {@link ResourceLocation} pointing to the image. * @return Width and height. */ public static Tuple<Integer, Integer> getImageDimensions(ResourceLocation resourceLocation) { int width = 0; int height = 0; Iterator<ImageReader> it = ImageIO.getImageReadersBySuffix("png"); if (it.hasNext()) { ImageReader reader = it.next(); try (ImageInputStream stream = ImageIO.createImageInputStream(Minecraft.getMinecraft().getResourceManager().getResource(resourceLocation).getInputStream())) { reader.setInput(stream); width = reader.getWidth(reader.getMinIndex()); height = reader.getHeight(reader.getMinIndex()); } catch (IOException e) { Log.logger.error(e); } finally { reader.dispose(); } } return new Tuple<>(width, height); } } which extends from a pane. package com.blockout; import com.blockout.views.Window; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.Gui; import org.lwjgl.BufferUtils; import org.lwjgl.opengl.GL11; import java.nio.FloatBuffer; import java.util.Deque; import java.util.concurrent.ConcurrentLinkedDeque; /** * A Pane is the root of all UI objects */ public class Pane extends Gui { protected Minecraft mc = Minecraft.getMinecraft(); // Attributes protected String id = ""; protected int x = 0; protected int y = 0; protected int width = 0; protected int height = 0; protected Alignment alignment = Alignment.TopLeft; protected boolean visible = true; protected boolean enabled = true; // Runtime protected Window window; protected View parent; protected static Pane lastClickedPane; protected static Pane focus; protected static boolean debugging = false; private static Deque<ScissorsInfo> scissorsInfoStack = new ConcurrentLinkedDeque<>(); /** * Default constructor */ public Pane() { //Required for panes. } /** * Constructs a Pane from PaneParams * * @param params Params for the Pane */ public Pane(PaneParams params) { id = params.getStringAttribute("id", id); PaneParams.SizePair parentSizePair = new PaneParams.SizePair(params.getParentWidth(), params.getParentHeight()); PaneParams.SizePair sizePair = params.getSizePairAttribute("size", null, parentSizePair); if (sizePair != null) { width = sizePair.getX(); height = sizePair.getY(); } else { width = params.getScalableIntegerAttribute("width", width, parentSizePair.getX()); height = params.getScalableIntegerAttribute("height", height, parentSizePair.getY()); } sizePair = params.getSizePairAttribute("pos", null, parentSizePair); if (sizePair != null) { x = sizePair.getX(); y = sizePair.getY(); } else { x = params.getScalableIntegerAttribute("x", x, parentSizePair.getX()); y = params.getScalableIntegerAttribute("y", y, parentSizePair.getY()); } alignment = params.getEnumAttribute("align", Alignment.class, alignment); visible = params.getBooleanAttribute("visible", visible); enabled = params.getBooleanAttribute("enabled", enabled); } public void parseChildren(PaneParams params) { // Can be overloaded } // ID public final String getID() { return id; } public final void setID(String id) { this.id = id; } // Dimensions public int getWidth() { return width; } public int getHeight() { return height; } public void setSize(int w, int h) { width = w; height = h; } // Position public int getX() { return x; } public int getY() { return y; } public void setPosition(int newX, int newY) { x = newX; y = newY; } public void moveBy(int dx, int dy) { x += dx; y += dy; } public Alignment getAlignment() { return alignment; } public void setAlignment(Alignment alignment) { this.alignment = alignment; } // Visibility public boolean isVisible() { return visible; } public void setVisible(boolean v) { visible = v; } public void show() { setVisible(true); } public void hide() { setVisible(false); } // Enabling public boolean isEnabled() { return enabled; } public void setEnabled(boolean e) { enabled = e; } public void enable() { setEnabled(true); } public void disable() { setEnabled(false); } // Focus /** * Returns the currently focused Pane * @return the currently focused Pane */ public static synchronized Pane getFocus() { return focus; } /** * Set the currently focused Pane * * @param f Pane to focus, or nil */ public static synchronized void setFocus(Pane f) { if (focus != null) { focus.onFocusLost(); } focus = f; if (focus != null) { focus.onFocus(); } } /** * Clear the currently focused Pane. */ public static void clearFocus() { setFocus(null); } /** * Set Focus to this Pane. */ public final void setFocus() { setFocus(this); } /** * Return <tt>true</tt> if this Pane is the current focus. * * @return <tt>true</tt> if this Pane is the current focus */ public final synchronized boolean isFocus() { return focus == this; } /** * Override to respond to the Pane losing focus */ public void onFocusLost() { // Can be overloaded } /** * Override to respond to the Pane becoming the current focus */ public void onFocus() { // Can be overloaded } // Drawing /** * Draw the current Pane if visible. * * @param mx mouse x * @param my mouse y */ public final void draw(int mx, int my) { if (visible) { GL11.glPushAttrib(GL11.GL_ALL_ATTRIB_BITS); drawSelf(mx, my); GL11.glPopAttrib(); if (debugging) { GL11.glPushAttrib(GL11.GL_ALL_ATTRIB_BITS); boolean isMouseOver = isPointInPane(mx, my); int color = isMouseOver ? 0xFF00FF00 : 0xFF0000FF; Render.drawOutlineRect(x, y, x+getWidth(), y+getHeight(), color); if (isMouseOver && !id.isEmpty()) { int stringWidth = mc.fontRendererObj.getStringWidth(id); mc.fontRendererObj.drawString(id, x + getWidth() - stringWidth, y + getHeight() - mc.fontRendererObj.FONT_HEIGHT, color); } GL11.glPopAttrib(); } } } /** * Draw self. The graphics port is already relative to the appropriate location * * Override this to actually draw. * * @param mx Mouse x (relative to parent) * @param my Mouse y (relative to parent) */ protected void drawSelf(int mx, int my) { // Can be overloaded } // Subpanes /** * Returns the first Pane of a given ID * Performs a depth-first search on the hierarchy of Panes and Views * * @param id ID of Pane to find * @return a Pane of the given ID */ public Pane findPaneByID(String id) { return this.id.equals(id) ? this : null; } /** * Returns the first Pane (depth-first search) of a given ID, * if it matches the specified type. * Performs a depth-first search on the hierarchy of Panes and Views. * * @param id ID of Pane to find * @param type Class of the desired Pane type * @param <T> The type of pane returned * @return a Pane of the given ID, if it matches the specified type */ public final <T extends Pane> T findPaneOfTypeByID(String id, Class<T> type) { Pane p = findPaneByID(id); try { return type.cast(p); } catch (ClassCastException e) { throw new IllegalArgumentException(String.format("No pane with id %s and type %s was found.", id, type), e); } } /** * Return the Pane that contains this one. * * @return the Pane that contains this one */ public final View getParent() { return parent; } /** * Return the Window that this Pane ultimately belongs to. * * @return the Window that this Pane belongs to. */ public final Window getWindow() { return window; } protected void setWindow(Window w) { window = w; } /** * Put this Pane inside a View. Only Views and subclasses can contain Panes * * @param newParent the View to put this Pane into, or null to remove from Parents */ public void putInside(View newParent) { if (parent != null) { parent.removeChild(this); } parent = newParent; if (parent != null) { parent.addChild(this); } } // Mouse /** * Is a point relative to the parent's origin within the pane? * * @param mx point x * @param my point y * @return true if the point is in the pane */ protected boolean isPointInPane(int mx, int my) { return mx >= x && mx < (x + width) && my >= y && my < (y + height); } public boolean isClickable() { return visible && enabled; } /** * Process a click on the Pane * * Override this to process the actual click * * @param mx mouse X coordinate, relative to Pane's top-left * @param my mouse Y coordinate, relative to Pane's top-left */ public void handleClick(int mx, int my) { // Can be overloaded } /** * Process a mouse down on the Pane. * * It is advised that only containers of other panes override this method * * @param mx mouse X coordinate, relative to parent's top-left * @param my mouse Y coordinate, relative to parent's top-left */ public void click(int mx, int my) { setLastClickedPane(this); handleClick(mx - x, my - y); } private static synchronized void setLastClickedPane(Pane pane) { lastClickedPane = pane; } public boolean canHandleClick(int mx, int my) { return visible && enabled && isPointInPane(mx, my); } public boolean onKeyTyped(char ch, int key) { return false; } public void onUpdate() { // Can be overloaded } private static class ScissorsInfo { private int x; private int y; private int width; private int height; ScissorsInfo(int x, int y, int w, int h) { this.x = x; this.y = y; this.width = w; this.height = h; } } protected synchronized void scissorsStart() { FloatBuffer fb = BufferUtils.createFloatBuffer(16 * 4); GL11.glGetFloat(GL11.GL_MODELVIEW_MATRIX, fb); int scissorsX = (int) fb.get(12) + getX(); int scissorsY = (int) fb.get(13) + getY(); int h = getHeight(); int w = getWidth(); if (!scissorsInfoStack.isEmpty()) { ScissorsInfo parentInfo = scissorsInfoStack.peek(); int right = scissorsX + w; int bottom = scissorsY + h; int parentRight = parentInfo.x + parentInfo.width; int parentBottom = parentInfo.y + parentInfo.height; scissorsX = Math.max(scissorsX, parentInfo.x); scissorsY = Math.max(scissorsY, parentInfo.y); w = Math.max(0, Math.min(right, parentRight) - scissorsX); h = Math.max(0, Math.min(bottom, parentBottom) - scissorsY); } GL11.glEnable(GL11.GL_SCISSOR_TEST); ScissorsInfo info = new ScissorsInfo(scissorsX, scissorsY, w, h); scissorsInfoStack.push(info); int scale = Screen.getScale(); GL11.glScissor(info.x * scale, mc.displayHeight - ((info.y + info.height) * scale), info.width * scale, info.height * scale); } protected synchronized void scissorsEnd() { scissorsInfoStack.pop(); GL11.glDisable(GL11.GL_SCISSOR_TEST); if (!scissorsInfoStack.isEmpty()) { GL11.glEnable(GL11.GL_SCISSOR_TEST); ScissorsInfo info = scissorsInfoStack.peek(); int scale = Screen.getScale(); GL11.glScissor(info.x * scale, mc.displayHeight - ((info.y + info.height) * scale), info.width * scale, info.height * scale); } } } and we call that image class por example. Image xpBar = new Image(); xpBar.setImage(GUI_ICONS_LOCATION, XP_BAR_ICON_COLUMN, XP_BAR_EMPTY_ROW, XP_BAR_WIDTH, XP_HEIGHT); xpBar.setPosition(LEFT_BORDER_X, LEFT_BORDER_Y); and then draw it.
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.