mirror of
https://github.com/HbmMods/Hbm-s-Nuclear-Tech-GIT.git
synced 2026-01-25 10:32:49 +00:00
i forgot to push again - intermission
This commit is contained in:
parent
46f11acb9b
commit
db5757a283
@ -0,0 +1,50 @@
|
||||
package com.hbm.entity.projectile;
|
||||
|
||||
import com.hbm.entity.logic.IChunkLoader;
|
||||
import com.hbm.main.MainRegistry;
|
||||
|
||||
import api.hbm.entity.IRadarDetectable;
|
||||
import net.minecraft.util.MovingObjectPosition;
|
||||
import net.minecraft.world.ChunkCoordIntPair;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.ForgeChunkManager;
|
||||
import net.minecraftforge.common.ForgeChunkManager.Ticket;
|
||||
import net.minecraftforge.common.ForgeChunkManager.Type;
|
||||
|
||||
public class EntityArtilleryRocket extends EntityThrowableInterp implements IChunkLoader, IRadarDetectable {
|
||||
|
||||
private Ticket loaderTicket;
|
||||
|
||||
public EntityArtilleryRocket(World world) {
|
||||
super(world);
|
||||
this.ignoreFrustumCheck = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void entityInit() {
|
||||
init(ForgeChunkManager.requestTicket(MainRegistry.instance, worldObj, Type.ENTITY));
|
||||
this.dataWatcher.addObject(10, new Integer(0));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onImpact(MovingObjectPosition mop) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public RadarTargetType getTargetType() {
|
||||
return RadarTargetType.ARTILLERY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init(Ticket ticket) {
|
||||
if(!worldObj.isRemote && ticket != null) {
|
||||
if(loaderTicket == null) {
|
||||
loaderTicket = ticket;
|
||||
loaderTicket.bindEntity(this);
|
||||
loaderTicket.getModData();
|
||||
}
|
||||
ForgeChunkManager.forceChunk(loaderTicket, new ChunkCoordIntPair(chunkCoordX, chunkCoordZ));
|
||||
}
|
||||
}
|
||||
}
|
||||
11
src/main/java/com/hbm/items/ISyncButtons.java
Normal file
11
src/main/java/com/hbm/items/ISyncButtons.java
Normal file
@ -0,0 +1,11 @@
|
||||
package com.hbm.items;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraftforge.client.event.MouseEvent;
|
||||
|
||||
public interface ISyncButtons {
|
||||
|
||||
public boolean canReceiveMouse(EntityPlayer player, ItemStack stack, MouseEvent event, int button, boolean buttonstate);
|
||||
public void receiveMouse(EntityPlayer player, ItemStack stack, int button, boolean buttonstate);
|
||||
}
|
||||
173
src/main/java/com/hbm/items/weapon/ItemPlasmaSpear.java
Normal file
173
src/main/java/com/hbm/items/weapon/ItemPlasmaSpear.java
Normal file
@ -0,0 +1,173 @@
|
||||
package com.hbm.items.weapon;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.hbm.inventory.fluid.FluidType;
|
||||
import com.hbm.inventory.fluid.Fluids;
|
||||
import com.hbm.items.ISyncButtons;
|
||||
import com.hbm.lib.ModDamageSource;
|
||||
import com.hbm.packet.AuxParticlePacketNT;
|
||||
import com.hbm.packet.PacketDispatcher;
|
||||
|
||||
import api.hbm.fluid.IFillableItem;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.util.AxisAlignedBB;
|
||||
import net.minecraft.util.EntityDamageSource;
|
||||
import net.minecraft.util.MovingObjectPosition;
|
||||
import net.minecraft.util.Vec3;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.client.event.MouseEvent;
|
||||
|
||||
public class ItemPlasmaSpear extends Item implements IFillableItem, ISyncButtons {
|
||||
|
||||
public static final int maxFuel = 3_000;
|
||||
|
||||
@Override
|
||||
public boolean showDurabilityBar(ItemStack stack) {
|
||||
return getFill(stack) < maxFuel;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getDurabilityForDisplay(ItemStack stack) {
|
||||
return 1 - (double) getFill(stack) / (double) maxFuel;
|
||||
}
|
||||
|
||||
public int getFill(ItemStack stack) {
|
||||
if(stack.stackTagCompound == null) {
|
||||
stack.stackTagCompound = new NBTTagCompound();
|
||||
setFill(stack, maxFuel);
|
||||
return maxFuel;
|
||||
}
|
||||
|
||||
return stack.stackTagCompound.getInteger("fuel");
|
||||
}
|
||||
|
||||
public void setFill(ItemStack stack, int fill) {
|
||||
if(stack.stackTagCompound == null) {
|
||||
stack.stackTagCompound = new NBTTagCompound();
|
||||
}
|
||||
|
||||
stack.stackTagCompound.setInteger("fuel", fill);
|
||||
}
|
||||
|
||||
public static ItemStack getEmptyTool(Item item) {
|
||||
ItemPlasmaSpear tool = (ItemPlasmaSpear) item;
|
||||
ItemStack stack = new ItemStack(item);
|
||||
tool.setFill(stack, 0);
|
||||
return stack;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack onItemRightClick(ItemStack stack, World world, EntityPlayer player) {
|
||||
|
||||
if(world.isRemote) return stack;
|
||||
|
||||
if(!stack.hasTagCompound()) {
|
||||
stack.stackTagCompound = new NBTTagCompound();
|
||||
}
|
||||
|
||||
stack.stackTagCompound.setBoolean("melee", !stack.stackTagCompound.getBoolean("melee"));
|
||||
world.playSoundAtEntity(player, "random.orb", 0.25F, 1.25F);
|
||||
|
||||
return stack;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onLeftClickEntity(ItemStack stack, EntityPlayer player, Entity entity) {
|
||||
|
||||
if(stack.hasTagCompound() && !stack.stackTagCompound.getBoolean("melee")) {
|
||||
return true; //cancel hitting, it's ranged
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onEntitySwing(EntityLivingBase entityLiving, ItemStack stack) {
|
||||
|
||||
if(!(entityLiving instanceof EntityPlayerMP))
|
||||
return false;
|
||||
|
||||
if(getFill(stack) <= 0)
|
||||
return false;
|
||||
|
||||
if(stack.hasTagCompound() && stack.stackTagCompound.getBoolean("melee")) {
|
||||
return true; //cancel hitting, it's ranged
|
||||
}
|
||||
|
||||
NBTTagCompound nbt = new NBTTagCompound();
|
||||
nbt.setString("type", "anim");
|
||||
nbt.setString("mode", "lSwing");
|
||||
PacketDispatcher.wrapper.sendTo(new AuxParticlePacketNT(nbt, 0, 0, 0), (EntityPlayerMP)entityLiving);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canReceiveMouse(EntityPlayer player, ItemStack stack, MouseEvent event, int button, boolean buttonstate) {
|
||||
|
||||
if(stack.hasTagCompound() && stack.stackTagCompound.getBoolean("melee")) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if(button == 0) {
|
||||
event.setCanceled(true);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void receiveMouse(EntityPlayer player, ItemStack stack, int button, boolean buttonstate) {
|
||||
Vec3 start = Vec3.createVectorHelper(player.posX, player.posY + player.getEyeHeight() - player.yOffset, player.posZ);
|
||||
Vec3 look = player.getLookVec();
|
||||
Vec3 end = start.addVector(look.xCoord * 100, look.yCoord * 100, look.zCoord * 100);
|
||||
|
||||
List<Entity> targets = player.worldObj.getEntitiesWithinAABBExcludingEntity(player, AxisAlignedBB.getBoundingBox(
|
||||
Math.min(start.xCoord, end.xCoord),
|
||||
Math.min(start.yCoord, end.yCoord),
|
||||
Math.min(start.zCoord, end.zCoord),
|
||||
Math.max(start.xCoord, end.xCoord),
|
||||
Math.max(start.yCoord, end.yCoord),
|
||||
Math.max(start.zCoord, end.zCoord)
|
||||
));
|
||||
|
||||
for(Entity target : targets) {
|
||||
|
||||
AxisAlignedBB aabb = target.boundingBox;
|
||||
MovingObjectPosition hitMop = aabb.calculateIntercept(start, end);
|
||||
|
||||
if(hitMop != null) {
|
||||
target.attackEntityFrom(new EntityDamageSource(ModDamageSource.s_laser, player).setDamageBypassesArmor(), 15F);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean acceptsFluid(FluidType type, ItemStack stack) {
|
||||
return type == Fluids.SCHRABIDIC;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int tryFill(FluidType type, int amount, ItemStack stack) {
|
||||
|
||||
int fill = this.getFill(stack);
|
||||
int toFill = this.maxFuel - fill;
|
||||
toFill = Math.min(toFill, amount);
|
||||
toFill = Math.min(toFill, 10);
|
||||
|
||||
this.setFill(stack, fill + toFill);
|
||||
|
||||
return amount - toFill;
|
||||
}
|
||||
|
||||
@Override public boolean providesFluid(FluidType type, ItemStack stack) { return false; }
|
||||
@Override public int tryEmpty(FluidType type, int amount, ItemStack stack) { return 0; }
|
||||
}
|
||||
@ -1626,6 +1626,7 @@ public class ClientProxy extends ServerProxy {
|
||||
|
||||
if("anim".equals(type)) {
|
||||
|
||||
/* crucible deploy */
|
||||
if("crucible".equals(data.getString("mode")) && player.getHeldItem() != null) {
|
||||
|
||||
BusAnimation animation = new BusAnimation()
|
||||
@ -1637,6 +1638,7 @@ public class ClientProxy extends ServerProxy {
|
||||
HbmAnimations.hotbar[player.inventory.currentItem] = new Animation(player.getHeldItem().getItem().getUnlocalizedName(), System.currentTimeMillis(), animation);
|
||||
}
|
||||
|
||||
/* crucible swing */
|
||||
if("cSwing".equals(data.getString("mode"))) {
|
||||
|
||||
if(HbmAnimations.getRelevantTransformation("SWING_ROT")[0] == 0) {
|
||||
@ -1659,7 +1661,8 @@ public class ClientProxy extends ServerProxy {
|
||||
}
|
||||
}
|
||||
|
||||
if("sSwing".equals(data.getString("mode"))) {
|
||||
/* chainsaw swing */
|
||||
if("sSwing".equals(data.getString("mode")) || "lSwing".equals(data.getString("mode"))) { //temp for lance
|
||||
|
||||
int forward = 150;
|
||||
int sideways = 100;
|
||||
|
||||
@ -27,6 +27,7 @@ import com.hbm.inventory.RecipesCommon.ComparableStack;
|
||||
import com.hbm.inventory.gui.GUIArmorTable;
|
||||
import com.hbm.inventory.material.Mats;
|
||||
import com.hbm.inventory.material.Mats.MaterialStack;
|
||||
import com.hbm.items.ISyncButtons;
|
||||
import com.hbm.items.ModItems;
|
||||
import com.hbm.items.armor.ArmorFSB;
|
||||
import com.hbm.items.armor.ArmorFSBPowered;
|
||||
@ -38,6 +39,7 @@ import com.hbm.lib.RefStrings;
|
||||
import com.hbm.packet.AuxButtonPacket;
|
||||
import com.hbm.packet.GunButtonPacket;
|
||||
import com.hbm.packet.PacketDispatcher;
|
||||
import com.hbm.packet.SyncButtonsPacket;
|
||||
import com.hbm.render.anim.HbmAnimations;
|
||||
import com.hbm.render.anim.HbmAnimations.Animation;
|
||||
import com.hbm.render.block.ct.CTStitchReceiver;
|
||||
@ -436,6 +438,14 @@ public class ModEventHandlerClient {
|
||||
item.startActionClient(player.getHeldItem(), player.worldObj, player, false);
|
||||
}
|
||||
}
|
||||
|
||||
if(held instanceof ISyncButtons) {
|
||||
ISyncButtons rec = (ISyncButtons) held;
|
||||
|
||||
if(rec.canReceiveMouse(player, player.getHeldItem(), event, event.button, event.buttonstate)) {
|
||||
PacketDispatcher.wrapper.sendToServer(new SyncButtonsPacket(event.buttonstate, event.button));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -101,6 +101,8 @@ public class PacketDispatcher {
|
||||
wrapper.registerMessage(ExplosionVanillaNewTechnologyCompressedAffectedBlockPositionDataForClientEffectsAndParticleHandlingPacket.Handler.class, ExplosionVanillaNewTechnologyCompressedAffectedBlockPositionDataForClientEffectsAndParticleHandlingPacket.class, i++, Side.CLIENT);
|
||||
//Packet to send NBT data from clients to the serverside held item
|
||||
wrapper.registerMessage(NBTItemControlPacket.Handler.class, NBTItemControlPacket.class, i++, Side.SERVER);
|
||||
//sends a button press to the held item, assuming it is an ISyncButtons
|
||||
wrapper.registerMessage(SyncButtonsPacket.Handler.class, SyncButtonsPacket.class, i++, Side.SERVER);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
56
src/main/java/com/hbm/packet/SyncButtonsPacket.java
Normal file
56
src/main/java/com/hbm/packet/SyncButtonsPacket.java
Normal file
@ -0,0 +1,56 @@
|
||||
package com.hbm.packet;
|
||||
|
||||
import com.hbm.items.ISyncButtons;
|
||||
|
||||
import cpw.mods.fml.common.FMLCommonHandler;
|
||||
import cpw.mods.fml.common.network.simpleimpl.IMessage;
|
||||
import cpw.mods.fml.common.network.simpleimpl.IMessageHandler;
|
||||
import cpw.mods.fml.common.network.simpleimpl.MessageContext;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
|
||||
public class SyncButtonsPacket implements IMessage {
|
||||
|
||||
boolean state;
|
||||
int button;
|
||||
|
||||
public SyncButtonsPacket() { }
|
||||
|
||||
public SyncButtonsPacket(boolean s, int b) {
|
||||
state = s;
|
||||
button = b;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fromBytes(ByteBuf buf) {
|
||||
state = buf.readBoolean();
|
||||
button = buf.readInt();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void toBytes(ByteBuf buf) {
|
||||
buf.writeBoolean(state);
|
||||
buf.writeInt(button);
|
||||
}
|
||||
|
||||
public static class Handler implements IMessageHandler<SyncButtonsPacket, IMessage> {
|
||||
|
||||
@Override
|
||||
public IMessage onMessage(SyncButtonsPacket m, MessageContext ctx) {
|
||||
|
||||
if(FMLCommonHandler.instance().getEffectiveSide() == Side.CLIENT)
|
||||
return null;
|
||||
|
||||
EntityPlayer p = ctx.getServerHandler().playerEntity;
|
||||
|
||||
if(p.getHeldItem() != null && p.getHeldItem().getItem() instanceof ISyncButtons) {
|
||||
|
||||
ISyncButtons item = (ISyncButtons)p.getHeldItem().getItem();
|
||||
item.receiveMouse(p, p.getHeldItem(), m.button, m.state);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user