Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Surface rocks are spawning and rendering. Packets are sent by the TES…
…R when a player looks at a rock and it doesn't have an item. Should be stable. TODO: make the rendering hitbox larger; rocks are disapearing when still in sight.
- Loading branch information
1 parent
b6e0e49
commit c552da0
Showing
8 changed files
with
234 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 74 additions & 0 deletions
74
src/main/java/net/dries007/tfc/network/PacketRequestWorldItem.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
/* | ||
* Work under Copyright. Licensed under the EUPL. | ||
* See the project README.md and LICENSE.txt for more information. | ||
* | ||
*/ | ||
|
||
package net.dries007.tfc.network; | ||
|
||
import net.minecraft.util.math.BlockPos; | ||
import net.minecraft.world.World; | ||
import net.minecraftforge.fml.common.FMLCommonHandler; | ||
import net.minecraftforge.fml.common.network.simpleimpl.IMessage; | ||
import net.minecraftforge.fml.common.network.simpleimpl.IMessageHandler; | ||
import net.minecraftforge.fml.common.network.simpleimpl.MessageContext; | ||
|
||
import io.netty.buffer.ByteBuf; | ||
import net.dries007.tfc.TerraFirmaCraft; | ||
import net.dries007.tfc.objects.te.TEWorldItem; | ||
|
||
public class PacketRequestWorldItem implements IMessage | ||
{ | ||
|
||
private BlockPos pos; | ||
private int dimension; | ||
|
||
public PacketRequestWorldItem(BlockPos pos, int dimension) | ||
{ | ||
this.pos = pos; | ||
this.dimension = dimension; | ||
} | ||
|
||
public PacketRequestWorldItem(TEWorldItem te) | ||
{ | ||
this(te.getPos(), te.getWorld().provider.getDimension()); | ||
} | ||
|
||
// Needs to be here for forge | ||
public PacketRequestWorldItem() { } | ||
|
||
@Override | ||
public void fromBytes(ByteBuf buf) | ||
{ | ||
pos = BlockPos.fromLong(buf.readLong()); | ||
dimension = buf.readInt(); | ||
} | ||
|
||
@Override | ||
public void toBytes(ByteBuf buf) | ||
{ | ||
buf.writeLong(pos.toLong()); | ||
buf.writeInt(dimension); | ||
} | ||
|
||
public static class Handler implements IMessageHandler<PacketRequestWorldItem, PacketUpdateWorldItem> | ||
{ | ||
|
||
@Override | ||
public PacketUpdateWorldItem onMessage(PacketRequestWorldItem message, MessageContext ctx) | ||
{ | ||
World world = FMLCommonHandler.instance().getMinecraftServerInstance().getWorld(message.dimension); | ||
TEWorldItem te = (TEWorldItem) world.getTileEntity(message.pos); | ||
if (te != null) | ||
{ | ||
TerraFirmaCraft.getLog().debug("Sent an update packet " + te.inventory.getStackInSlot(0).getDisplayName()); | ||
return new PacketUpdateWorldItem(te); | ||
} | ||
else | ||
{ | ||
return null; | ||
} | ||
} | ||
|
||
} | ||
} |
73 changes: 73 additions & 0 deletions
73
src/main/java/net/dries007/tfc/network/PacketUpdateWorldItem.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
/* | ||
* Work under Copyright. Licensed under the EUPL. | ||
* See the project README.md and LICENSE.txt for more information. | ||
* | ||
*/ | ||
|
||
package net.dries007.tfc.network; | ||
|
||
import net.minecraft.client.Minecraft; | ||
import net.minecraft.item.ItemStack; | ||
import net.minecraft.util.math.BlockPos; | ||
import net.minecraftforge.fml.common.network.ByteBufUtils; | ||
import net.minecraftforge.fml.common.network.simpleimpl.IMessage; | ||
import net.minecraftforge.fml.common.network.simpleimpl.IMessageHandler; | ||
import net.minecraftforge.fml.common.network.simpleimpl.MessageContext; | ||
|
||
import io.netty.buffer.ByteBuf; | ||
import net.dries007.tfc.TerraFirmaCraft; | ||
import net.dries007.tfc.objects.te.TEWorldItem; | ||
|
||
public class PacketUpdateWorldItem implements IMessage | ||
{ | ||
|
||
private BlockPos pos; | ||
private ItemStack stack; | ||
|
||
public PacketUpdateWorldItem(TEWorldItem te) | ||
{ | ||
this(te.getPos(), te.inventory.getStackInSlot(0)); | ||
} | ||
|
||
public PacketUpdateWorldItem(BlockPos pos, ItemStack stack) | ||
{ | ||
this.pos = pos; | ||
this.stack = stack; | ||
} | ||
|
||
// Needed for forge to call this class | ||
public PacketUpdateWorldItem() {} | ||
|
||
@Override | ||
public void fromBytes(ByteBuf buf) | ||
{ | ||
pos = BlockPos.fromLong(buf.readLong()); | ||
stack = ByteBufUtils.readItemStack(buf); | ||
} | ||
|
||
@Override | ||
public void toBytes(ByteBuf buf) | ||
{ | ||
buf.writeLong(pos.toLong()); | ||
ByteBufUtils.writeItemStack(buf, stack); | ||
} | ||
|
||
public static class Handler implements IMessageHandler<PacketUpdateWorldItem, IMessage> | ||
{ | ||
|
||
@Override | ||
public IMessage onMessage(PacketUpdateWorldItem message, MessageContext ctx) | ||
{ | ||
Minecraft.getMinecraft().addScheduledTask(() -> { | ||
TEWorldItem te = (TEWorldItem) Minecraft.getMinecraft().world.getTileEntity(message.pos); | ||
if (te != null) | ||
{ | ||
TerraFirmaCraft.getLog().debug("Got the update packet: " + message.stack.getDisplayName()); | ||
te.inventory.setStackInSlot(0, message.stack); | ||
} | ||
}); | ||
return null; | ||
} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.