Search in sources :

Example 6 with MessageTileSync

use of blusunrize.immersiveengineering.common.util.network.MessageTileSync in project ImmersiveEngineering by BluSunrize.

the class TileEntityBelljar method sendSyncPacket.

protected void sendSyncPacket(int type) {
    NBTTagCompound nbt = new NBTTagCompound();
    if (type == 0) {
        nbt.setFloat("growth", growth);
        nbt.setInteger("energy", energyStorage.getEnergyStored());
        nbt.setBoolean("renderActive", renderActive);
    } else if (type == 1) {
        nbt.setInteger("fertilizerAmount", fertilizerAmount);
        nbt.setFloat("fertilizerMod", fertilizerMod);
    } else if (type == 2)
        nbt.setTag("tank", tank.writeToNBT(new NBTTagCompound()));
    ImmersiveEngineering.packetHandler.sendToAllAround(new MessageTileSync(this, nbt), new TargetPoint(worldObj.provider.getDimension(), getPos().getX(), getPos().getY(), getPos().getZ(), 128));
}
Also used : NBTTagCompound(net.minecraft.nbt.NBTTagCompound) TargetPoint(net.minecraftforge.fml.common.network.NetworkRegistry.TargetPoint) MessageTileSync(blusunrize.immersiveengineering.common.util.network.MessageTileSync)

Example 7 with MessageTileSync

use of blusunrize.immersiveengineering.common.util.network.MessageTileSync in project ImmersiveEngineering by BluSunrize.

the class TileEntityExcavator method update.

@Override
public void update() {
    super.update();
    if (isDummy())
        return;
    if (!worldObj.isRemote) {
        BlockPos wheelPos = this.getBlockPosForPos(31);
        TileEntity center = worldObj.getTileEntity(wheelPos);
        if (center instanceof TileEntityBucketWheel) {
            float rot = 0;
            int target = -1;
            TileEntityBucketWheel wheel = ((TileEntityBucketWheel) center);
            EnumFacing fRot = this.facing.rotateYCCW();
            if (wheel.facing == fRot) {
                if (active != wheel.active)
                    worldObj.addBlockEvent(wheel.getPos(), wheel.getBlockType(), 0, active ? 1 : 0);
                rot = wheel.rotation;
                if (rot % 45 > 40)
                    target = Math.round(rot / 360f * 8) % 8;
            }
            if (wheel.facing != fRot || wheel.mirrored != this.mirrored) {
                for (int h = -3; h <= 3; h++) for (int w = -3; w <= 3; w++) {
                    TileEntity te = worldObj.getTileEntity(wheelPos.add(0, h, 0).offset(facing, w));
                    if (te instanceof TileEntityBucketWheel) {
                        ((TileEntityBucketWheel) te).facing = fRot;
                        ((TileEntityBucketWheel) te).mirrored = this.mirrored;
                        te.markDirty();
                        ((TileEntityBucketWheel) te).markContainingBlockForUpdate(null);
                        worldObj.addBlockEvent(te.getPos(), te.getBlockType(), 255, 0);
                    }
                }
            }
            if (!isRSDisabled()) {
                ExcavatorHandler.MineralMix mineral = ExcavatorHandler.getRandomMineral(worldObj, wheelPos.getX() >> 4, wheelPos.getZ() >> 4);
                int consumed = IEConfig.Machines.excavator_consumption;
                int extracted = energyStorage.extractEnergy(consumed, true);
                if (extracted >= consumed) {
                    energyStorage.extractEnergy(consumed, false);
                    active = true;
                    if (target >= 0 && target < 8) {
                        int targetDown = (target + 4) % 8;
                        NBTTagCompound packet = new NBTTagCompound();
                        if (wheel.digStacks[targetDown] == null) {
                            ItemStack blocking = this.digBlocksInTheWay(wheel);
                            BlockPos lowGroundPos = wheelPos.add(0, -5, 0);
                            if (blocking != null) {
                                wheel.digStacks[targetDown] = blocking;
                                wheel.markDirty();
                                this.markContainingBlockForUpdate(null);
                            } else if (mineral != null && !worldObj.isAirBlock(lowGroundPos.offset(facing, -2)) && !worldObj.isAirBlock(lowGroundPos.offset(facing, 2)) && !worldObj.isAirBlock(lowGroundPos.offset(facing, -1)) && !worldObj.isAirBlock(lowGroundPos.offset(facing, 1)) && !worldObj.isAirBlock(lowGroundPos)) {
                                ItemStack ore = mineral.getRandomOre(worldObj.rand);
                                float configChance = worldObj.rand.nextFloat();
                                float failChance = worldObj.rand.nextFloat();
                                if (ore != null && configChance > IEConfig.Machines.excavator_fail_chance && failChance > mineral.failChance) {
                                    wheel.digStacks[targetDown] = ore;
                                    wheel.markDirty();
                                    this.markContainingBlockForUpdate(null);
                                }
                                ExcavatorHandler.depleteMinerals(worldObj, wheelPos.getX() >> 4, wheelPos.getZ() >> 4);
                            }
                            if (wheel.digStacks[targetDown] != null) {
                                packet.setInteger("fill", targetDown);
                                packet.setTag("fillStack", wheel.digStacks[targetDown].writeToNBT(new NBTTagCompound()));
                            }
                        }
                        if (wheel.digStacks[target] != null) {
                            this.doProcessOutput(wheel.digStacks[target].copy());
                            Block b = Block.getBlockFromItem(wheel.digStacks[target].getItem());
                            if (b != null && b != Blocks.AIR)
                                wheel.particleStack = wheel.digStacks[target].copy();
                            wheel.digStacks[target] = null;
                            wheel.markDirty();
                            this.markContainingBlockForUpdate(null);
                            packet.setInteger("empty", target);
                        }
                        if (!packet.hasNoTags())
                            ImmersiveEngineering.packetHandler.sendToAll(new MessageTileSync(wheel, packet));
                    }
                } else if (active)
                    active = false;
            } else if (active) {
                active = false;
            //					update = true;
            }
        //				if(update)
        //				{
        //					this.markDirty();
        //					worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
        //				}
        }
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) ExcavatorHandler(blusunrize.immersiveengineering.api.tool.ExcavatorHandler) EnumFacing(net.minecraft.util.EnumFacing) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) Block(net.minecraft.block.Block) BlockPos(net.minecraft.util.math.BlockPos) ItemStack(net.minecraft.item.ItemStack) MessageTileSync(blusunrize.immersiveengineering.common.util.network.MessageTileSync)

Example 8 with MessageTileSync

use of blusunrize.immersiveengineering.common.util.network.MessageTileSync in project ImmersiveEngineering by BluSunrize.

the class TileEntityBucketWheel method update.

@Override
public void update() {
    if (!formed || pos != 24)
        return;
    if (active) {
        rotation += IEConfig.Machines.excavator_speed;
        rotation %= 360;
    }
    if (worldObj.isRemote) {
        if (particleStack != null) {
            ImmersiveEngineering.proxy.spawnBucketWheelFX(this, particleStack);
            particleStack = null;
        }
    } else if (active && worldObj.getTotalWorldTime() % 20 == 0) {
        NBTTagCompound nbt = new NBTTagCompound();
        nbt.setFloat("rotation", rotation);
        MessageTileSync sync = new MessageTileSync(this, nbt);
        ImmersiveEngineering.packetHandler.sendToAllAround(sync, new TargetPoint(worldObj.provider.getDimension(), getPos().getX(), getPos().getY(), getPos().getZ(), 100));
    }
}
Also used : NBTTagCompound(net.minecraft.nbt.NBTTagCompound) TargetPoint(net.minecraftforge.fml.common.network.NetworkRegistry.TargetPoint) MessageTileSync(blusunrize.immersiveengineering.common.util.network.MessageTileSync)

Example 9 with MessageTileSync

use of blusunrize.immersiveengineering.common.util.network.MessageTileSync in project ImmersiveEngineering by BluSunrize.

the class GuiAssembler method actionPerformed.

@Override
protected void actionPerformed(GuiButton button) {
    NBTTagCompound tag = new NBTTagCompound();
    tag.setInteger("buttonID", button.id);
    ImmersiveEngineering.packetHandler.sendToServer(new MessageTileSync(tile, tag));
    if (button.id == 3) {
        tile.recursiveIngredients = !tile.recursiveIngredients;
        this.initGui();
    }
}
Also used : NBTTagCompound(net.minecraft.nbt.NBTTagCompound) MessageTileSync(blusunrize.immersiveengineering.common.util.network.MessageTileSync)

Example 10 with MessageTileSync

use of blusunrize.immersiveengineering.common.util.network.MessageTileSync in project ImmersiveEngineering by BluSunrize.

the class GuiSorter method actionPerformed.

@Override
protected void actionPerformed(GuiButton button) {
    if (button instanceof ButtonSorter && FMLCommonHandler.instance().getEffectiveSide() == Side.CLIENT) {
        int side = button.id / 3;
        int bit = button.id % 3;
        int mask = (1 << bit);
        this.tile.sideFilter[side] = this.tile.sideFilter[side] ^ mask;
        NBTTagCompound tag = new NBTTagCompound();
        tag.setIntArray("sideConfig", this.tile.sideFilter);
        ImmersiveEngineering.packetHandler.sendToServer(new MessageTileSync(tile, tag));
        this.initGui();
    }
}
Also used : NBTTagCompound(net.minecraft.nbt.NBTTagCompound) MessageTileSync(blusunrize.immersiveengineering.common.util.network.MessageTileSync)

Aggregations

MessageTileSync (blusunrize.immersiveengineering.common.util.network.MessageTileSync)13 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)13 GuiReactiveList (blusunrize.immersiveengineering.client.gui.elements.GuiReactiveList)2 ItemStack (net.minecraft.item.ItemStack)2 TargetPoint (net.minecraftforge.fml.common.network.NetworkRegistry.TargetPoint)2 ExcavatorHandler (blusunrize.immersiveengineering.api.tool.ExcavatorHandler)1 IConfigurableTool (blusunrize.immersiveengineering.api.tool.IConfigurableTool)1 ToolConfigBoolean (blusunrize.immersiveengineering.api.tool.IConfigurableTool.ToolConfig.ToolConfigBoolean)1 ToolConfigFloat (blusunrize.immersiveengineering.api.tool.IConfigurableTool.ToolConfig.ToolConfigFloat)1 ButtonSorter (blusunrize.immersiveengineering.client.gui.GuiSorter.ButtonSorter)1 GuiButtonCheckbox (blusunrize.immersiveengineering.client.gui.elements.GuiButtonCheckbox)1 GuiButtonItem (blusunrize.immersiveengineering.client.gui.elements.GuiButtonItem)1 GuiButtonState (blusunrize.immersiveengineering.client.gui.elements.GuiButtonState)1 GuiSliderIE (blusunrize.immersiveengineering.client.gui.elements.GuiSliderIE)1 TileEntityTurretChem (blusunrize.immersiveengineering.common.blocks.metal.TileEntityTurretChem)1 TileEntityTurretGun (blusunrize.immersiveengineering.common.blocks.metal.TileEntityTurretGun)1 IESlot (blusunrize.immersiveengineering.common.gui.IESlot)1 Block (net.minecraft.block.Block)1 GuiButton (net.minecraft.client.gui.GuiButton)1 Slot (net.minecraft.inventory.Slot)1