Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

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.

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)

  • Author

That didn't work. Caused the code to not even run.

The seven became one and the one became two.

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)

1 hour ago, Merthew said:

Should be up now.

You're not running the code on the server if you do something when a button is pressed in a gui.

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

  • Author

Should i send something to the server?

The seven became one and the one became two.

  • Author

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.

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)

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.

  • Author

Ok, i actually fixed it this time using packets and stuff. Thanks

The seven became one and the one became two.

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...

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.