Jump to content

[1.12.2] update world weather


Merthew

Recommended Posts

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.

Link to comment
Share on other sites

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)

Link to comment
Share on other sites

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)

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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)

Link to comment
Share on other sites

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.

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

    • 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  
    • so my minecraft crashes when opening my world, i played without any troubles for about 5 days and today it started tweaking.. pls help me
    • Hi guys! I am having some issues with the server crashing over and over and I was hoping to get some guidance.  Thanks in advance! Crash 1: java.lang.Error: ServerHangWatchdog detected that a single server tick took 60.00 seconds (should be max 0.05)     at net.minecraft.server.dedicated.ServerWatchdog.run(ServerWatchdog.java:43) ~[server-1.20.1-20230612.114412-srg.jar%23217!/:?] {re:classloading}     at java.lang.Thread.run(Thread.java:840) ~[?:?] { Crash 2: java.lang.IllegalStateException: Capability missing for eeb7f026-34b4-42f5-9164-e7736461df83     at me.lucko.luckperms.forge.capabilities.UserCapabilityImpl.lambda$get$0(UserCapabilityImpl.java:66) ~[?:?] {re:classloading,re:classloading,re:classloading}     at net.minecraftforge.common.util.LazyOptional.orElseThrow(LazyOptional.java:261) ~[forge-1.20.1-47.3.10-universal.jar%23222!/:?] {re:mixin,re:classloading}     at me.lucko.luckperms.forge.capabilities.UserCapabilityImpl.get(UserCapabilityImpl.java:66) ~[?:?] {re:classloading,re:classloading,re:classloading}     at me.lucko.luckperms.forge.util.BrigadierInjector$InjectedPermissionRequirement.test(BrigadierInjector.java:143) ~[?:?] {}     at me.lucko.luckperms.forge.util.BrigadierInjector$InjectedPermissionRequirement.test(BrigadierInjector.java:129) ~[?:?] {}     at com.mojang.brigadier.tree.CommandNode.canUse(CommandNode.java:65) ~[brigadier-1.1.8.jar%2376!/:?] {}     at com.mojang.brigadier.CommandDispatcher.parseNodes(CommandDispatcher.java:359) ~[brigadier-1.1.8.jar%2376!/:?] {}     at com.mojang.brigadier.CommandDispatcher.parse(CommandDispatcher.java:349) ~[brigadier-1.1.8.jar%2376!/:?] {}     at com.mojang.brigadier.CommandDispatcher.parse(CommandDispatcher.java:317) ~[brigadier-1.1.8.jar%2376!/:?] {}     at net.minecraft.commands.Commands.m_230957_(Commands.java:237) ~[server-1.20.1-20230612.114412-srg.jar%23217!/:?] {re:classloading}     at net.mcreator.boh.procedures.TeleportbenProcedure.lambda$execute$2(TeleportbenProcedure.java:65) ~[boh-0.0.6.1-forge-1.20.1_2.jar%23165!/:?] {re:classloading}     at net.mcreator.boh.BohMod.lambda$tick$2(BohMod.java:96) ~[boh-0.0.6.1-forge-1.20.1_2.jar%23165!/:?] {re:classloading}     at java.util.ArrayList.forEach(ArrayList.java:1511) ~[?:?] {re:mixin}     at net.mcreator.boh.BohMod.tick(BohMod.java:96) ~[boh-0.0.6.1-forge-1.20.1_2.jar%23165!/:?] {re:classloading}     at net.mcreator.boh.__BohMod_tick_ServerTickEvent.invoke(.dynamic) ~[boh-0.0.6.1-forge-1.20.1_2.jar%23165!/:?] {re:classloading,pl:eventbus:B}     at net.minecraftforge.eventbus.ASMEventHandler.invoke(ASMEventHandler.java:73) ~[eventbus-6.0.5.jar%2352!/:?] {}     at net.minecraftforge.eventbus.EventBus.post(EventBus.java:315) ~[eventbus-6.0.5.jar%2352!/:?] {}     at net.minecraftforge.eventbus.EventBus.post(EventBus.java:296) ~[eventbus-6.0.5.jar%2352!/:?] {}     at net.minecraftforge.event.ForgeEventFactory.onPostServerTick(ForgeEventFactory.java:950) ~[forge-1.20.1-47.3.10-universal.jar%23222!/:?] {re:classloading}     at net.minecraft.server.MinecraftServer.m_5705_(MinecraftServer.java:835) ~[server-1.20.1-20230612.114412-srg.jar%23217!/:?] {re:mixin,pl:accesstransformer:B,xf:fml:xaerominimap:xaero_minecraftserver,re:classloading,pl:accesstransformer:B,xf:fml:xaerominimap:xaero_minecraftserver,pl:mixin:A}     at net.minecraft.server.MinecraftServer.m_130011_(MinecraftServer.java:661) ~[server-1.20.1-20230612.114412-srg.jar%23217!/:?] {re:mixin,pl:accesstransformer:B,xf:fml:xaerominimap:xaero_minecraftserver,re:classloading,pl:accesstransformer:B,xf:fml:xaerominimap:xaero_minecraftserver,pl:mixin:A}     at net.minecraft.server.MinecraftServer.m_206580_(MinecraftServer.java:251) ~[server-1.20.1-20230612.114412-srg.jar%23217!/:?] {re:mixin,pl:accesstransformer:B,xf:fml:xaerominimap:xaero_minecraftserver,re:classloading,pl:accesstransformer:B,xf:fml:xaerominimap:xaero_minecraftserver,pl:mixin:A}     at java.lang.Thread.run(Thread.java:840) ~[?:?] {}
  • Topics

×
×
  • Create New...

Important Information

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