Jump to content

TE properties seemingly being set randomly


meee39

Recommended Posts

In my mod I have a TE that does a function while it has power. When it runs out of power it will consume one piece of fuel from its inventory (if there is any there). Every tick the power level decreases by one and when it gets to the end it triggers the fuel consumption. So the block has two different states: powered and unpowered. You can tell which state it is in because they have different textures. The problem is while the power ticks left are counting down the block state flickers between the powered and unpowered state. I also put in a System.out.printline() to check what is going on and it would end up like this:

Spoiler

10

0

9

0

8

0

...

Instead of:

Spoiler

10

9

8

7

6

...

Like it should do.

 

I don't know anything about packets and data syncing with FML although I know that things to do with that can cause problems so I think it might be something to do with data not being synced between client and server.

 

Code:

public class TileEntityEnderSuppressor extends TileEntity implements ITickable, IMobSuppressorTE {
	private World world = Minecraft.getMinecraft().world;
	public BlockEnderSuppressor block;
	public boolean isPublic;
	public static final int maxTicks = 300;
	public int powerTicksLeft = 0;
	
	public ItemStackHandler itemStackHandler = new ItemStackHandler(1) {
		@Override
		protected void onContentsChanged(int slot) {
			TileEntityEnderSuppressor.this.markDirty();
		}
	};
	
	public TileEntityEnderSuppressor() {}
	
	public TileEntityEnderSuppressor(BlockEnderSuppressor block) {
		this.block = block;
		this.isPublic = true;
	}
	
	@Override
	public void update() {
		if (world.getBlockState(getPos()).getBlock() instanceof BlockEnderSuppressor != true) {
			return;
		}
		
		if (world != null) {
			Random RNG = new Random();
			world.spawnParticle(EnumParticleTypes.PORTAL, RNG.nextFloat() + pos.getX(), RNG.nextFloat() + pos.getY(), RNG.nextFloat() + pos.getZ(), 0.1, 0.1, 0.1, 0);
		}
		
		if (powerTicksLeft > 0) {
			powerTicksLeft--;
			world.setBlockState(this.getPos(), world.getBlockState(getPos()).withProperty(block.is_powered, false));
		} else {
			if (itemStackHandler.getStackInSlot(0).isEmpty()) {
				world.setBlockState(this.getPos(), world.getBlockState(getPos()).withProperty(block.is_powered, true));
			} else {
				if (itemStackHandler.getStackInSlot(0).getItem() instanceof ItemEnderPearl) {
					itemStackHandler.getStackInSlot(0).shrink(1);
					setFullPowerTicks();
				}
			}
		}
	}
	
	@Override
	public NBTTagCompound writeToNBT(NBTTagCompound compound) {
		super.writeToNBT(compound);
		
		compound.setTag("items", itemStackHandler.serializeNBT());
		
		compound.setBoolean("isPublic", isPublic);
		compound.setInteger("powerTicksLeft", powerTicksLeft);
		
		return compound;
	}
	
	@Override
	public void readFromNBT(NBTTagCompound compound) {
		super.readFromNBT(compound);
		
		if (compound.hasKey("items")) {
			itemStackHandler.deserializeNBT((NBTTagCompound)compound.getTag("items"));
		}
		
		isPublic = compound.getBoolean("isPublic");
		powerTicksLeft = compound.getInteger("powerTicksLeft");
	}

	@Override
	public boolean isPublic() {
		return isPublic;
	}

	@Override
	public void setFullPowerTicks() {
		this.powerTicksLeft = maxTicks;
	}

	@Override
	public int getPowerTicksLeft() {
		return powerTicksLeft;
	}
	
	@Override
    public boolean hasCapability(Capability<?> capability, EnumFacing facing) {
        if (capability == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY) {
            return true;
        }
        return super.hasCapability(capability, facing);
    }

    @Override
    public <T> T getCapability(Capability<T> capability, EnumFacing facing) {
        if (capability == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY) {
            return (T) itemStackHandler;
        }
        return super.getCapability(capability, facing);
    }
	
	public boolean canInteractWith(EntityPlayer playerIn) {
        return !isInvalid() && playerIn.getDistanceSq(pos.add(0.5D, 0.5D, 0.5D)) <= 64D;
    }
public class BlockEnderSuppressor extends Block implements ITileEntityProvider {
	public static final PropertyBool is_powered = PropertyBool.create("is_powered");
	
	public IMobSuppressorTE TE;
	
	protected BlockEnderSuppressor(String unlocalizedName, String registryName) {
		super(Material.IRON);
		this.setUnlocalizedName(unlocalizedName);
		this.setRegistryName(registryName);
		this.setHardness(2);
		this.setResistance(6000f);
		this.setHarvestLevel("pickaxe", 3);
		this.isBlockContainer = true;
		this.setDefaultState(this.blockState.getBaseState().withProperty(is_powered, false));
		this.setCreativeTab(CreativeTab.mobSuppressorCreativeTab);
	}
	
	@Override
	protected BlockStateContainer createBlockState() {
		return new BlockStateContainer(this, is_powered);
	}
	
	@Override
	public IBlockState getStateFromMeta(int meta) {
		return this.getDefaultState().withProperty(is_powered, meta == 0);
	}
	
	@Override
	public int getMetaFromState(IBlockState state) {
		return state.getValue(is_powered) ? 1: 0;
	}
	
	@Override
	public IBlockState getActualState(IBlockState state, IBlockAccess worldIn, BlockPos pos) {
		return state.withProperty(is_powered, state.getValue(is_powered));
	}
	
	@Override
	public TileEntity createNewTileEntity(World worldIn, int meta) {
		TE = new TileEntityEnderSuppressor(this);
		
		return (TileEntity)TE;
	}
	
	@Override
	public void breakBlock(World world, BlockPos pos, IBlockState state) {
		super.breakBlock(world, pos, state);
		world.removeTileEntity(pos);
	}

	@Override
    public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
		if (!worldIn.isRemote) {
			playerIn.openGui(MobSuppressors.instance, ModGUIHandler.enderSuppressorGUIID, worldIn, pos.getX(), pos.getY(), pos.getZ());
		}
		
		return true;
	}	
}

If you need any other classes to find the problem just ask.

Link to comment
Share on other sites

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

7 hours ago, meee39 said:

I also put in a System.out.printline() to check what is going on

Does the printing run on both client and server? If so, then one may be counting down while the other is stuck at zero.

 

If you want to see what is really going on, then step through your code in the debugger, examining variables as you go.

The debugger is a powerful and necessary tool in any IDE, so learn how to use it. You'll be able to tell us more and get better help here if you investigate your runtime problems in the debugger before posting.

Link to comment
Share on other sites

1) you implement those methods

2) you call these when the data changes

Edited by Draco18s

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

That didn't make any difference. Here is the class now:

package com.leo.mobsuppressors.tileentity;

import java.util.Random;

import com.leo.mobsuppressors.blocks.BlockEnderSuppressor;

import jline.internal.Nullable;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemEnderPearl;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.network.NetworkManager;
import net.minecraft.network.play.server.SPacketUpdateTileEntity;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumParticleTypes;
import net.minecraft.util.ITickable;
import net.minecraftforge.common.capabilities.Capability;
import net.minecraftforge.items.CapabilityItemHandler;
import net.minecraftforge.items.ItemStackHandler;

public class TileEntityEnderSuppressor extends TileEntity implements ITickable, IMobSuppressorTE {
	public static BlockEnderSuppressor block;
	public boolean isPublic;
	public static final int maxTicks = 300;
	public int powerTicksLeft = 0;
	public Random RNG = new Random();
	
	public ItemStackHandler itemStackHandler = new ItemStackHandler(1) {
		@Override
		protected void onContentsChanged(int slot) {
			TileEntityEnderSuppressor.this.markDirty();
		}
	};
	
	public TileEntityEnderSuppressor() {}
	
	public TileEntityEnderSuppressor(BlockEnderSuppressor block) {
		this.block = block;
		this.isPublic = true;
	}
	
	@Override
	public void update() {
		if (!(world.getBlockState(getPos()).getBlock() instanceof BlockEnderSuppressor)) {
			return;
		}
	
		world.spawnParticle(EnumParticleTypes.PORTAL, RNG.nextFloat() + pos.getX(), RNG.nextFloat() + pos.getY(), RNG.nextFloat() + pos.getZ(), 0.1, 0.1, 0.1, 0);
		
		if (!world.isRemote) {
			world.setBlockState(this.getPos(), world.getBlockState(getPos()).withProperty(block.is_powered, true));
			
			if (powerTicksLeft > 0) {
				powerTicksLeft--;
				world.markBlockRangeForRenderUpdate(pos, pos);
				world.notifyBlockUpdate(pos, world.getBlockState(getPos()), world.getBlockState(getPos()).withProperty(block.is_powered, true), 3);
				world.scheduleBlockUpdate(pos,this.getBlockType(),0,0);
				markDirty();
				world.setBlockState(this.getPos(), world.getBlockState(getPos()).withProperty(block.is_powered, true));
			} else {
				if (itemStackHandler.getStackInSlot(0).isEmpty()) {
					world.setBlockState(this.getPos(), world.getBlockState(getPos()).withProperty(block.is_powered, false));
				} else {
					if (itemStackHandler.getStackInSlot(0).getItem() instanceof ItemEnderPearl) {
						itemStackHandler.getStackInSlot(0).shrink(1);
						setFullPowerTicks();
						world.markBlockRangeForRenderUpdate(pos, pos);
						world.notifyBlockUpdate(pos, world.getBlockState(getPos()), world.getBlockState(getPos()).withProperty(block.is_powered, true), 3);
						world.scheduleBlockUpdate(pos,this.getBlockType(),0,0);
						markDirty();
					}
				}
			}
		}
		System.out.println(powerTicksLeft);
	}
	
	@Override
	public NBTTagCompound writeToNBT(NBTTagCompound compound) {
		super.writeToNBT(compound);
		
		compound.setTag("items", itemStackHandler.serializeNBT());
		
		compound.setBoolean("isPublic", isPublic);
		compound.setInteger("powerTicksLeft", powerTicksLeft);
		
		return compound;
	}
	
	@Override
	public void readFromNBT(NBTTagCompound compound) {
		super.readFromNBT(compound);
		
		if (compound.hasKey("items")) {
			itemStackHandler.deserializeNBT((NBTTagCompound)compound.getTag("items"));
		}
		
		isPublic = compound.getBoolean("isPublic");
		powerTicksLeft = compound.getInteger("powerTicksLeft");
	}

	@Override
	@Nullable
	public SPacketUpdateTileEntity getUpdatePacket() {
		return new SPacketUpdateTileEntity(this.pos, 3, this.getUpdateTag());
	}

	@Override
	public NBTTagCompound getUpdateTag() {
		return this.writeToNBT(new NBTTagCompound());
	}
	
	@Override
	public void onDataPacket(NetworkManager net, SPacketUpdateTileEntity pkt) {
		super.onDataPacket(net, pkt);
		handleUpdateTag(pkt.getNbtCompound());
	}
	
	@Override
	public boolean isPublic() {
		return isPublic;
	}

	@Override
	public void setFullPowerTicks() {
		this.powerTicksLeft = maxTicks;
	}

	@Override
	public int getPowerTicksLeft() {
		return powerTicksLeft;
	}
	
	@Override
    public boolean hasCapability(Capability<?> capability, EnumFacing facing) {
        if (capability == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY) {
            return true;
        }
        return super.hasCapability(capability, facing);
    }

    @Override
    public <T> T getCapability(Capability<T> capability, EnumFacing facing) {
        if (capability == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY) {
            return (T) itemStackHandler;
        }
        return super.getCapability(capability, facing);
    }
	
	public boolean canInteractWith(EntityPlayer playerIn) {
        return !isInvalid() && playerIn.getDistanceSq(pos.add(0.5D, 0.5D, 0.5D)) <= 64D;
    }
}

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • Instale el mod en mi servidor y este se queda iniciando por horas, en la consola me habla de algo de permisos y trate de seguir la ruta que me da pero no existe.   [13:05:32 INFO]: CustomNPC Permissions available: [13:05:32 INFO]: customnpcs.edit.blocks [13:05:32 INFO]: customnpcs.edit.villager [13:05:32 INFO]: customnpcs.global.bank [13:05:32 INFO]: customnpcs.global.dialog [13:05:32 INFO]: customnpcs.global.faction [13:05:32 INFO]: customnpcs.global.linked [13:05:32 INFO]: customnpcs.global.naturalspawn [13:05:32 INFO]: customnpcs.global.playerdata [13:05:32 INFO]: customnpcs.global.quest [13:05:32 INFO]: customnpcs.global.recipe [13:05:32 INFO]: customnpcs.global.transport [13:05:32 INFO]: customnpcs.npc.advanced [13:05:32 INFO]: customnpcs.npc.ai [13:05:32 INFO]: customnpcs.npc.clone [13:05:32 INFO]: customnpcs.npc.create [13:05:32 INFO]: customnpcs.npc.delete [13:05:32 INFO]: customnpcs.npc.display [13:05:32 INFO]: customnpcs.npc.freeze [13:05:32 INFO]: customnpcs.npc.gui [13:05:32 INFO]: customnpcs.npc.inventory [13:05:32 INFO]: customnpcs.npc.reset [13:05:32 INFO]: customnpcs.npc.stats [13:05:32 INFO]: customnpcs.scenes [13:05:32 INFO]: customnpcs.soulstone.all [13:05:32 INFO]: customnpcs.spawner.create [13:05:32 INFO]: customnpcs.spawner.mob [13:05:32 INFO]: customnpcs.tool.mounter [13:05:32 INFO]: customnpcs.tool.nbtbook [13:05:32 INFO]: customnpcs.tool.pather [13:05:32 INFO]: customnpcs.tool.scripter
    • I have created a very simple mod that is just supposed to send a message to a player when they join. Upon adding it to a server (that has other mods on it), the following crash message appears: [12:13:01] [main/ERROR] [minecraft/Main]: Failed to start the minecraft server net.minecraftforge.fml.LoadingFailedException: Loading errors encountered: [         Epic Mod (epicmod) has failed to load correctly §7java.lang.NoSuchMethodException: net.ed.epicmod.EpicMod.<init>() ]         at net.minecraftforge.fml.ModLoader.waitForTransition(ModLoader.java:243) ~[fmlcore-1.19.2-43.2.14.jar%23548!/:?] {}         at net.minecraftforge.fml.ModLoader.lambda$dispatchAndHandleError$24(ModLoader.java:208) ~[fmlcore-1.19.2-43.2.14.jar%23548!/:?] {}         at java.util.Optional.ifPresent(Optional.java:178) ~[?:?] {re:mixin}         at net.minecraftforge.fml.ModLoader.dispatchAndHandleError(ModLoader.java:208) ~[fmlcore-1.19.2-43.2.14.jar%23548!/:?] {}         at net.minecraftforge.fml.ModLoader.lambda$gatherAndInitializeMods$14(ModLoader.java:185) ~[fmlcore-1.19.2-43.2.14.jar%23548!/:?] {}         at java.lang.Iterable.forEach(Iterable.java:75) ~[?:?] {re:mixin,re:computing_frames}         at net.minecraftforge.fml.ModLoader.gatherAndInitializeMods(ModLoader.java:185) ~[fmlcore-1.19.2-43.2.14.jar%23548!/:?] {}         at net.minecraftforge.server.loading.ServerModLoader.load(ServerModLoader.java:32) ~[forge-1.19.2-43.2.14-universal.jar%23552!/:?] {re:classloading}         at net.minecraft.server.Main.main(Main.java:113) ~[server-1.19.2-20220805.130853-srg.jar%23547!/:?] {re:classloading,re:mixin,pl:mixin:A}         at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:?] {}         at jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77) ~[?:?] {}         at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:?] {}         at java.lang.reflect.Method.invoke(Method.java:568) ~[?:?] {}         at net.minecraftforge.fml.loading.targets.CommonServerLaunchHandler.lambda$launchService$0(CommonServerLaunchHandler.java:29) ~[fmlloader-1.19.2-43.2.14.jar%2367!/:?] {}         at cpw.mods.modlauncher.LaunchServiceHandlerDecorator.launch(LaunchServiceHandlerDecorator.java:30) [modlauncher-10.0.8.jar%2354!/:?] {}         at cpw.mods.modlauncher.LaunchServiceHandler.launch(LaunchServiceHandler.java:53) [modlauncher-10.0.8.jar%2354!/:?] {}         at cpw.mods.modlauncher.LaunchServiceHandler.launch(LaunchServiceHandler.java:71) [modlauncher-10.0.8.jar%2354!/:?] {}         at cpw.mods.modlauncher.Launcher.run(Launcher.java:106) [modlauncher-10.0.8.jar%2354!/:?] {}         at cpw.mods.modlauncher.Launcher.main(Launcher.java:77) [modlauncher-10.0.8.jar%2354!/:?] {}         at cpw.mods.modlauncher.BootstrapLaunchConsumer.accept(BootstrapLaunchConsumer.java:26) [modlauncher-10.0.8.jar%2354!/:?] {}         at cpw.mods.modlauncher.BootstrapLaunchConsumer.accept(BootstrapLaunchConsumer.java:23) [modlauncher-10.0.8.jar%2354!/:?] {}         at cpw.mods.bootstraplauncher.BootstrapLauncher.main(BootstrapLauncher.java:141) [bootstraplauncher-1.1.2.jar:?] {} Why could this be? I have tried using the mod on another forge server with only this mod installed and it works there. Is my mod somehow interfering with other mods? MC version is 1.19.2
    • how to make animated doors?, maybe geckolib, but i don't know how to code it?
    • For crash 1, set max-tick-time to -1 in your server.properties Crash 2 shows a conflict or incompatibility between LuckPerms and the mod boh-0.0.6.1-forge-1.20.1_2.jar
    • Add the crash-report or latest.log (logs-folder) with sites like https://mclo.gs/ and paste the link to it here  
  • Topics

×
×
  • Create New...

Important Information

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