Jump to content

Recommended Posts

Posted

I have created a custom tileentity that on pressing a button in the center, and with all slots empty, it should change the weather to clear. However, nothing happens...

 

Code File:

Spoiler

package merthew.mod.block.divinity.altar;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import java.util.Random;

import javax.annotation.Nullable;

import merthew.mod.inventory.EobItemHandler;
import net.minecraft.init.Blocks;
import net.minecraft.init.Items;
import net.minecraft.item.Item;
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.ITickable;
import net.minecraft.world.storage.WorldInfo;
import net.minecraftforge.common.capabilities.Capability;
import net.minecraftforge.items.CapabilityItemHandler;

public class TileEntityAltar extends TileEntity implements ITickable{
	private final EobItemHandler itemHandler;
	boolean isCheckStart;
	boolean isPressed;
	int ticksPressed;
	public boolean storm = false;
    public boolean rain = false;
	
	enum Ritual {
		RAIN, CLEAR
	}
	
	Map<ArrayList<Item>, Ritual> recipes = new HashMap<ArrayList<Item>, Ritual>();
	
	public TileEntityAltar() {
		super();
		itemHandler = new EobItemHandler(8);
		
		ArrayList<Item> rain = new ArrayList<Item>();
		for(int i = 0; i < 8; i ++) {
			rain.add(Items.WATER_BUCKET);
		}
		recipes.put(rain, Ritual.RAIN);
		
		ArrayList<Item> clear = new ArrayList<Item>();
		for(int i = 0; i < 8; i ++) {
			clear.add(Item.getItemFromBlock(Blocks.AIR));
		}
		recipes.put(clear, Ritual.CLEAR);
	}

	@Override
	public void update() {
		if(isPressed) {
			ticksPressed ++;
		}
		
		if(ticksPressed >= 10) {
			isPressed = false;
			ticksPressed = 0;
		}
		
		if(isCheckStart) {
			System.out.println("Check Start is a go.");
			if(shouldStart()) {
				System.out.println("Should Start is a go.");
				ArrayList<Item> inputs = new ArrayList<Item>();
				inputs.add(itemHandler.getStackInSlot(0).getItem());
				inputs.add(itemHandler.getStackInSlot(1).getItem());
				inputs.add(itemHandler.getStackInSlot(2).getItem());
				inputs.add(itemHandler.getStackInSlot(3).getItem());
				inputs.add(itemHandler.getStackInSlot(4).getItem());
				inputs.add(itemHandler.getStackInSlot(5).getItem());
				inputs.add(itemHandler.getStackInSlot(6).getItem());
				inputs.add(itemHandler.getStackInSlot(7).getItem());
				Ritual r = recipes.get(inputs);
				System.out.println("Ritual: " + r);
				
				int i = (300 + (new Random()).nextInt(600)) * 20;
	            WorldInfo worldinfo = world.getWorldInfo();
				
				switch(r) {
				case RAIN:
					worldinfo.setCleanWeatherTime(0);
	                worldinfo.setRainTime(i);
	                worldinfo.setThunderTime(i);
	                worldinfo.setRaining(true);
	                worldinfo.setThundering(false);
					System.out.println("Ritual rain performed.");
		            break;
				case CLEAR:
					worldinfo.setCleanWeatherTime(i);
	                worldinfo.setRainTime(0);
	                worldinfo.setThunderTime(0);
	                worldinfo.setRaining(false);
	                worldinfo.setThundering(false);
	                System.out.println("Ritual clear performed.");
					break;
				}
			}
			isCheckStart = false;
		}
	}
	
	private boolean shouldStart() {
		ArrayList<Item> inputs = new ArrayList<Item>();
		inputs.add(itemHandler.getStackInSlot(0).getItem());
		inputs.add(itemHandler.getStackInSlot(1).getItem());
		inputs.add(itemHandler.getStackInSlot(2).getItem());
		inputs.add(itemHandler.getStackInSlot(3).getItem());
		inputs.add(itemHandler.getStackInSlot(4).getItem());
		inputs.add(itemHandler.getStackInSlot(5).getItem());
		inputs.add(itemHandler.getStackInSlot(6).getItem());
		inputs.add(itemHandler.getStackInSlot(7).getItem());
		
		if(recipes.containsKey(inputs)) {
			System.out.println("Is a recipe");
			return true;
		}
		else {
			System.out.println("Not a recipe");
			return false;
		}
	}
	
	@Override
	public void readFromNBT(NBTTagCompound nbtTagCompound)
	{
		super.readFromNBT(nbtTagCompound);
		itemHandler.deserializeNBT(nbtTagCompound.getCompoundTag("ItemHandler"));
	}
	
	@Override
	public NBTTagCompound writeToNBT(NBTTagCompound nbtTagCompound)
	{
		super.writeToNBT(nbtTagCompound);
		nbtTagCompound.setTag("ItemHandler", itemHandler.serializeNBT());	
		return nbtTagCompound;
	}
	
	public EobItemHandler getItemHandler()
	{
		return itemHandler;
	}
	
	@SuppressWarnings("unchecked")
	@Override
	public <T> T getCapability(Capability<T> capability, @Nullable EnumFacing facing)
	{
		if (capability == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY)
		{
			return (T) itemHandler;
		}

		return super.getCapability(capability, facing);
	}

	@Override
	public boolean hasCapability(Capability<?> capability, @Nullable EnumFacing facing)
	{
		return false;
	}

	@Override
	public SPacketUpdateTileEntity getUpdatePacket()
	{
		return new SPacketUpdateTileEntity(pos, 0, getUpdateTag());
	}

	@Override
	public void onDataPacket(NetworkManager net, SPacketUpdateTileEntity pkt)
	{
		readFromNBT(pkt.getNbtCompound());
	}

	@Override
	public NBTTagCompound getUpdateTag()
	{
		return this.writeToNBT(new NBTTagCompound());
	}

	public void saveCraftingInfo(String text, boolean modeRecieved) {
		this.updateTile();
	}

	void updateTile(){
		world.notifyBlockUpdate(pos, world.getBlockState(pos), world.getBlockState(pos), 3);
		world.scheduleBlockUpdate(pos,this.getBlockType(),0,0);
		markDirty();
	}
}

 

Any help would be apreciated.

The seven became one and the one became two.

Posted

try making sure your on a server (!world.isRemote)

About Me

Spoiler

My Discord - Cadiboo#8887

My WebsiteCadiboo.github.io

My ModsCadiboo.github.io/projects

My TutorialsCadiboo.github.io/tutorials

Versions below 1.14.4 are no longer supported on this forum. Use the latest version to receive support.

When asking support remember to include all relevant log files (logs are found in .minecraft/logs/), code if applicable and screenshots if possible.

Only download mods from trusted sites like CurseForge (minecraft.curseforge.com). A list of bad sites can be found here, with more information available at stopmodreposts.org

Edit your own signature at www.minecraftforge.net/forum/settings/signature/ (Make sure to check its compatibility with the Dark Theme)

Posted

Then you've got a big issue. Can you please push to your repo?

About Me

Spoiler

My Discord - Cadiboo#8887

My WebsiteCadiboo.github.io

My ModsCadiboo.github.io/projects

My TutorialsCadiboo.github.io/tutorials

Versions below 1.14.4 are no longer supported on this forum. Use the latest version to receive support.

When asking support remember to include all relevant log files (logs are found in .minecraft/logs/), code if applicable and screenshots if possible.

Only download mods from trusted sites like CurseForge (minecraft.curseforge.com). A list of bad sites can be found here, with more information available at stopmodreposts.org

Edit your own signature at www.minecraftforge.net/forum/settings/signature/ (Make sure to check its compatibility with the Dark Theme)

Posted

Fixed it, had to set the world to one hosted from the server.

World world = Minecraft.getMinecraft().getIntegratedServer().getWorld(0);

The seven became one and the one became two.

Posted
10 minutes ago, Merthew said:

Fixed it, had to set the world to one hosted from the server.

World world = Minecraft.getMinecraft().getIntegratedServer().getWorld(0);

What if the server isn't integrated?

About Me

Spoiler

My Discord - Cadiboo#8887

My WebsiteCadiboo.github.io

My ModsCadiboo.github.io/projects

My TutorialsCadiboo.github.io/tutorials

Versions below 1.14.4 are no longer supported on this forum. Use the latest version to receive support.

When asking support remember to include all relevant log files (logs are found in .minecraft/logs/), code if applicable and screenshots if possible.

Only download mods from trusted sites like CurseForge (minecraft.curseforge.com). A list of bad sites can be found here, with more information available at stopmodreposts.org

Edit your own signature at www.minecraftforge.net/forum/settings/signature/ (Make sure to check its compatibility with the Dark Theme)

Posted
20 minutes ago, Merthew said:

Fixed it, had to set the world to one hosted from the server.

World world = Minecraft.getMinecraft().getIntegratedServer().getWorld(0);

You are reaching across logical sides here. More over this will only work on the physical client. You need to send the packet to the server when the button is pressed and cnahge the weather in a runnable that you will queue to be invoked in your packet handler.

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

    • I tried do download the essential mod to my mod pack but i didnt work. I paly on 1.21 and it should work. I use neoforge for my modding. The weird things is my friend somehow added the mod to his modpack and many others that I somehow can´t. Is there anything i can do? 
    • Thanks, I've now installed a slightly newer version and the server is at least starting up now.
    • i have the same issue. Found 1 Create mod class dependency(ies) in createdeco-1.3.3-1.19.2.jar, which are missing from the current create-1.19.2-0.5.1.i.jar Found 11 Create mod class dependency(ies) in createaddition-fabric+1.19.2-20230723a.jar, which are missing from the current create-1.19.2-0.5.1.i.jar Detailed walkthrough of mods which rely on missing Create mod classes: Mod: createaddition-fabric+1.19.2-20230723a.jar Missing classes of create: com/simibubi/create/compat/jei/category/sequencedAssembly/JeiSequencedAssemblySubCategory com/simibubi/create/compat/recipeViewerCommon/SequencedAssemblySubCategoryType com/simibubi/create/compat/rei/CreateREI com/simibubi/create/compat/rei/EmptyBackground com/simibubi/create/compat/rei/ItemIcon com/simibubi/create/compat/rei/category/CreateRecipeCategory com/simibubi/create/compat/rei/category/WidgetUtil com/simibubi/create/compat/rei/category/animations/AnimatedBlazeBurner com/simibubi/create/compat/rei/category/animations/AnimatedKinetics com/simibubi/create/compat/rei/category/sequencedAssembly/ReiSequencedAssemblySubCategory com/simibubi/create/compat/rei/display/CreateDisplay Mod: createdeco-1.3.3-1.19.2.jar Missing classes of create: com/simibubi/create/content/kinetics/fan/SplashingRecipe
    • The crash points to moonlight lib - try other builds or make a test without this mod and the mods requiring it
    • Do you have shaders enabled? There is an issue with the mod simpleclouds - remove this mod or disable shaders, if enabled  
  • Topics

  • Who's Online (See full list)

×
×
  • Create New...

Important Information

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