
Jodelahithit
Forge Modder-
Posts
6 -
Joined
-
Last visited
Everything posted by Jodelahithit
-
I want to make a method that does something for a set time like the potion effects do. For example, i want to make a "shout" that is cast by the player and then starts doing something for a set duration (let's say 2 minutes or so?) and then stops. I expect i should not use SystemTime and i need to use a tickHandler. I already made one but i'm not sure how i would do this.
-
[1.7.10][Solved] setBlock server side using packets?
Jodelahithit replied to Jodelahithit's topic in Modder Support
I found a way to do it. I send the client's objectMouseOver coordinates to the server using a packet. The packet then acceses it to set the block. Thanks for the help. -
[1.7.10][Solved] setBlock server side using packets?
Jodelahithit replied to Jodelahithit's topic in Modder Support
Thank you for explaining why i shouldn't use Minecraft.class. I managed to get the world from the server which fixed the setBlock problem. Code now: public void handleServerSide(EntityPlayer player) { EntityPlayerMP thePlayer = (EntityPlayerMP) player; World world = thePlayer.worldObj; int x = player.rayTrace(5, 1.0f).blockX; int y = player.rayTrace(5, 1.0f).blockY; int z = player.rayTrace(5, 1.0f).blockZ; // if (!(world.getBlock(x, y, z) == Blocks.air)) { world.setBlock(x, y, z, TDEBlocks.blockLog1, 0, 3); System.out.println(x + "_" + y + "_" + z); // } } As you can see i used the default reach distance (5) but it's not giving the same results as Minecraft.getMinecraft().objectMouseOver. I'm also not sure what the second argument for rayTrace should be. Looking at the code doesn't help much. -
I have recently started working with packets because our mods requires them. This is the code for the packet: import com.thedarkera.init.TDEBlocks; public class getManaPacket extends AbstractPacket { private int mana; public getManaPacket() { } public getManaPacket(int mana) { this.mana = mana; } public void encodeInto(ChannelHandlerContext ctx, ByteBuf buffer) { buffer.writeByte(mana); } public void decodeInto(ChannelHandlerContext ctx, ByteBuf buffer) { mana = buffer.readByte(); } public void handleClientSide(EntityPlayer player) { } public void handleServerSide(EntityPlayer player) { World world = Minecraft.getMinecraft().theWorld; int x = Minecraft.getMinecraft().objectMouseOver.blockX; int y = Minecraft.getMinecraft().objectMouseOver.blockY; int z = Minecraft.getMinecraft().objectMouseOver.blockZ; if (!(world.getBlock(x, y, z) == Blocks.air)) { world.setBlock(x, y, z+1, TDEBlocks.blockLog1, 0, 3); System.out.println(x + y + z); } } } This is the AbstractPackage class: package com.thedarkera.packet; import io.netty.buffer.ByteBuf; import io.netty.channel.ChannelHandlerContext; import net.minecraft.entity.player.EntityPlayer; public abstract class AbstractPacket { public abstract void encodeInto(ChannelHandlerContext ctx, ByteBuf buffer); public abstract void decodeInto(ChannelHandlerContext ctx, ByteBuf buffer); public abstract void handleClientSide(EntityPlayer player); public abstract void handleServerSide(EntityPlayer player); } And of course the PacketPipeline: package com.thedarkera.packet; import io.netty.buffer.ByteBuf; import io.netty.buffer.Unpooled; import io.netty.channel.ChannelHandler; import io.netty.channel.ChannelHandlerContext; import io.netty.handler.codec.MessageToMessageCodec; import java.util.Collections; import java.util.Comparator; import java.util.EnumMap; import java.util.LinkedList; import java.util.List; import net.minecraft.client.Minecraft; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.network.INetHandler; import net.minecraft.network.NetHandlerPlayServer; import com.thedarkera.TheDarkEra; import com.thedarkera.utils.Ref; import cpw.mods.fml.common.FMLCommonHandler; import cpw.mods.fml.common.network.FMLEmbeddedChannel; import cpw.mods.fml.common.network.FMLOutboundHandler; import cpw.mods.fml.common.network.NetworkRegistry; import cpw.mods.fml.common.network.internal.FMLProxyPacket; import cpw.mods.fml.relauncher.Side; @ChannelHandler.Sharable public class PacketPipeline extends MessageToMessageCodec<FMLProxyPacket, AbstractPacket> { private EnumMap<Side, FMLEmbeddedChannel> channels; private LinkedList<Class<? extends AbstractPacket>> packets = new LinkedList<Class<? extends AbstractPacket>>(); private boolean isPostInitialized = false; public boolean registerPacket(Class<? extends AbstractPacket> clazz) { if (this.packets.size() > 256) { TheDarkEra.logger.error("Maximum amount of packets reached!"); return false; } if (this.packets.contains(clazz)) { TheDarkEra.logger.error("This packet has already been registered!"); return false; } if (this.isPostInitialized == true) { TheDarkEra.logger.error("Packet registered too late!"); return false; } this.packets.add(clazz); return true; } public void initialize() { this.channels = NetworkRegistry.INSTANCE.newChannel(Ref.PACKET_CHANNEL_NAME, this); registerPackets(); } public void postInitialize(){ if(isPostInitialized) return; isPostInitialized = true; Collections.sort(this.packets, new Comparator<Class<? extends AbstractPacket>>(){ @Override public int compare(Class<? extends AbstractPacket> o1, Class<? extends AbstractPacket> o2){ int com = String.CASE_INSENSITIVE_ORDER.compare(o1.getCanonicalName(), o2.getCanonicalName()); if (com == 0) com = o1.getCanonicalName().compareTo(o2.getCanonicalName()); return com; } }); } public void registerPackets() { registerPacket(getManaPacket.class); } @Override protected void encode(ChannelHandlerContext ctx, AbstractPacket msg, List<Object> out) throws Exception { ByteBuf buffer = Unpooled.buffer(); Class<? extends AbstractPacket> clazz = msg.getClass(); if (!this.packets.contains(clazz)) { throw new NullPointerException("This packet has never been registered" + clazz.getCanonicalName()); } byte discriminator = (byte) this.packets.indexOf(clazz); buffer.writeByte(discriminator); msg.encodeInto(ctx, buffer); FMLProxyPacket proxyPacket = new FMLProxyPacket(buffer.copy(), ctx.channel().attr(NetworkRegistry.FML_CHANNEL).get()); out.add(proxyPacket); } @Override protected void decode(ChannelHandlerContext ctx, FMLProxyPacket msg, List<Object> out) throws Exception { ByteBuf payload = msg.payload(); byte discriminator = payload.readByte(); Class<? extends AbstractPacket> clazz = this.packets.get(discriminator); if (clazz == null) { throw new NullPointerException("This packet has never been registered" + clazz.getCanonicalName()); } AbstractPacket abstractPacket = clazz.newInstance(); abstractPacket.decodeInto(ctx, payload.slice()); EntityPlayer player; switch (FMLCommonHandler.instance().getEffectiveSide()) { case CLIENT: player = Minecraft.getMinecraft().thePlayer; abstractPacket.handleClientSide(player); break; case SERVER: INetHandler iNetHandler = ctx.channel().attr(NetworkRegistry.NET_HANDLER).get(); player = ((NetHandlerPlayServer) iNetHandler).playerEntity; abstractPacket.handleServerSide(player); break; default: } out.add(abstractPacket); } public void sendToServer(AbstractPacket message){ this.channels.get(Side.CLIENT).attr(FMLOutboundHandler.FML_MESSAGETARGET).set(FMLOutboundHandler.OutboundTarget.TOSERVER); this.channels.get(Side.CLIENT).writeAndFlush(message); } } As you can see I'm trying to use setBlock at the coordinates the player is looking at. Problem is that it's only working client side and not server side. I haven't been able to find an answer to this yet, can anyone explain what i should use to set a block server side?
-
Should be
-
Hello, [glow=red,2,300]I'm fairly new to minecraft modding but i know java well enough to start with it[/glow] I've been trying to make a new grass block with forge for a while now, i've tried multiple ways but everything seems to give problems. What i've done now is just copy the BlockGrass.java from minecraft and set that as my Blockgrass.java It seems to be working but i get this problem: http://i1287.photobucket.com/albums/a621/jodelahithit1/Grass_zpsf5e9d6d3.png[/img] As you can see the biome colors are also rendered on the sides and bottom and the overlay is only visible when there is snow on top of the block. Here's my code so far for the Blockgrass: Main.java I left all my other blocks and items out to make it less messy! package jodelahithit.mods.rs; import jodelahithit.mods.rs.block.Blockdirt; import jodelahithit.mods.rs.block.Blockgrass; import jodelahithit.mods.rs.block.Blockground; import jodelahithit.mods.rs.block.Blockstone; import jodelahithit.mods.rs.block.Blockwood; import jodelahithit.mods.rs.block.Blockwool; import jodelahithit.mods.rs.item.Logo; import jodelahithit.mods.rs.misc.SRSCreativeTab; import jodelahithit.mods.rs.registry.Blockground_registry; import jodelahithit.mods.rs.registry.Blockstone_registry; import jodelahithit.mods.rs.registry.Blockwood_registry; import jodelahithit.mods.rs.registry.Blockwool_registry; import net.minecraft.block.Block; import net.minecraft.block.BlockGrass; import net.minecraft.block.material.Material; import net.minecraft.creativetab.CreativeTabs; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import cpw.mods.fml.common.Mod; import cpw.mods.fml.common.Mod.EventHandler; import cpw.mods.fml.common.event.FMLInitializationEvent; import cpw.mods.fml.common.registry.GameRegistry; import cpw.mods.fml.common.registry.LanguageRegistry; @Mod(modid = SRS.modid, name = "SteadycraftRS", version = "0.1") public class SRS { public static jodelahithit.mods.rs.block.Blockgrass Blockgrass; @EventHandler public void load(FMLInitializationEvent E) { Blockgrass = (Blockgrass) new Blockgrass(1001).setUnlocalizedName("SRS_blockgrass"); RB(Blockgrass, "Grass"); } public void RB(Block block, String name) { GameRegistry.registerBlock(block, block.getUnlocalizedName()); LanguageRegistry.addName(block, name); } } Blockgrass.java package jodelahithit.mods.rs.block; import java.util.Random; import jodelahithit.mods.rs.SRS; import net.minecraft.block.Block; import net.minecraft.block.material.Material; import net.minecraft.client.renderer.texture.IconRegister; import net.minecraft.creativetab.CreativeTabs; import net.minecraft.util.Icon; import net.minecraft.world.ColorizerGrass; import net.minecraft.world.IBlockAccess; import net.minecraft.world.World; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; public class Blockgrass extends Block { @SideOnly(Side.CLIENT) private Icon iconGrassTop; @SideOnly(Side.CLIENT) private Icon iconSnowSide; @SideOnly(Side.CLIENT) private Icon iconGrassSideOverlay; public Blockgrass(int par1) { super(par1, Material.grass); this.setTickRandomly(true); this.setCreativeTab(CreativeTabs.tabBlock); } @SideOnly(Side.CLIENT) /** * From the specified side and block metadata retrieves the blocks texture. Args: side, metadata */ public Icon getIcon(int par1, int par2) { return par1 == 1 ? this.iconGrassTop : (par1 == 0 ? SRS.Blockdirt.getBlockTextureFromSide(par1) : this.blockIcon); } /** * Ticks the block if it's been scheduled */ public void updateTick(World par1World, int par2, int par3, int par4, Random par5Random) { if (!par1World.isRemote) { if (par1World.getBlockLightValue(par2, par3 + 1, par4) < 4 && par1World.getBlockLightOpacity(par2, par3 + 1, par4) > 2) { par1World.setBlock(par2, par3, par4, SRS.Blockgrass.blockID); } else if (par1World.getBlockLightValue(par2, par3 + 1, par4) >= 9) { for (int l = 0; l < 4; ++l) { int i1 = par2 + par5Random.nextInt(3) - 1; int j1 = par3 + par5Random.nextInt(5) - 3; int k1 = par4 + par5Random.nextInt(3) - 1; int l1 = par1World.getBlockId(i1, j1 + 1, k1); if (par1World.getBlockId(i1, j1, k1) == SRS.Blockdirt.blockID && par1World.getBlockLightValue(i1, j1 + 1, k1) >= 4 && par1World.getBlockLightOpacity(i1, j1 + 1, k1) <= 2) { par1World.setBlock(i1, j1, k1, SRS.Blockgrass.blockID); } } } } } /** * Returns the ID of the items to drop on destruction. */ public int idDropped(int par1, Random par2Random, int par3) { return Block.dirt.idDropped(0, par2Random, par3); } @SideOnly(Side.CLIENT) /** * Retrieves the block texture to use based on the display side. Args: iBlockAccess, x, y, z, side */ public Icon getBlockTexture(IBlockAccess par1IBlockAccess, int par2, int par3, int par4, int par5) { if (par5 == 1) { return this.iconGrassTop; } else if (par5 == 0) { return this.blockIcon; } else { Material material = par1IBlockAccess.getBlockMaterial(par2, par3 + 1, par4); return material != Material.snow && material != Material.craftedSnow ? this.blockIcon : this.iconSnowSide; } } @SideOnly(Side.CLIENT) /** * When this method is called, your block should register all the icons it needs with the given IconRegister. This * is the only chance you get to register icons. */ public void registerIcons(IconRegister par1IconRegister) { this.blockIcon = par1IconRegister.registerIcon(SRS.modid + ":" + "grass/" + (this.getUnlocalizedName().substring(5)) + "_side"); this.iconGrassTop = par1IconRegister.registerIcon(SRS.modid + ":" + "grass/" + (this.getUnlocalizedName().substring(5)) + "_top"); this.iconGrassSideOverlay = par1IconRegister.registerIcon(SRS.modid + ":" + "grass/" + (this.getUnlocalizedName().substring(5)) + "_side_overlay"); this.iconSnowSide = par1IconRegister.registerIcon(SRS.modid + ":" + "grass/" + (this.getUnlocalizedName().substring(5)) + "_side_snowed"); } @SideOnly(Side.CLIENT) public int getBlockColor() { double d0 = 0.5D; double d1 = 1.0D; return ColorizerGrass.getGrassColor(d0, d1); } @SideOnly(Side.CLIENT) /** * Returns the color this block should be rendered. Used by leaves. */ public int getRenderColor(int par1) { return this.getBlockColor(); } @SideOnly(Side.CLIENT) /** * Returns a integer with hex for 0xrrggbb with this color multiplied against the blocks color. Note only called * when first determining what to render. */ public int colorMultiplier(IBlockAccess par1IBlockAccess, int par2, int par3, int par4) { int l = 0; int i1 = 0; int j1 = 0; for (int k1 = -1; k1 <= 1; ++k1) { for (int l1 = -1; l1 <= 1; ++l1) { int i2 = par1IBlockAccess.getBiomeGenForCoords(par2 + l1, par4 + k1).getBiomeGrassColor(); l += (i2 & 16711680) >> 16; i1 += (i2 & 65280) >> 8; j1 += i2 & 255; } } return (l / 9 & 255) << 16 | (i1 / 9 & 255) << 8 | j1 / 9 & 255; } @SideOnly(Side.CLIENT) public static Icon getIconSideOverlay() { return SRS.Blockgrass.iconGrassSideOverlay; } } If i forgot anything in this post please tell me. Any help with this problem would be really appreciated!