Skip to content
Merged
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.charles445.simpledifficulty;

import com.charles445.simpledifficulty.config.ModConfig;
import com.charles445.simpledifficulty.command.CommandSimpleDifficulty;
import com.charles445.simpledifficulty.debug.DebugVerifier;
import com.charles445.simpledifficulty.network.PacketHandler;
Expand Down Expand Up @@ -48,6 +49,7 @@ public void preInit(FMLPreInitializationEvent event)
proxy.preInit();

com.charles445.simpledifficulty.compat.mod.Weather2Compat.init();
ModConfig.sendLocalServerConfigToAPI();
}

@Mod.EventHandler
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,27 +57,23 @@ public BlockFluidBasic(Fluid fluid, Material material, String iceBlock) {

@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) {
return true;
}

ItemStack heldItem = playerIn.getHeldItem(hand);

// Handle empty bottle interaction
if (heldItem.getItem() == Items.GLASS_BOTTLE) {
if (!heldItem.isEmpty() && heldItem.getItem() == Items.GLASS_BOTTLE) {
ItemStack resultBottle = getBottleResult();

if (!resultBottle.isEmpty()) {
// Consume the empty bottle
heldItem.shrink(1);

// Add the filled bottle to inventory or drop it
if (heldItem.isEmpty()) {
playerIn.setHeldItem(hand, resultBottle);
} else if (!playerIn.inventory.addItemStackToInventory(resultBottle)) {
playerIn.dropItem(resultBottle, false);
if (!worldIn.isRemote) {
// Server side: consume bottle and give result
heldItem.shrink(1);

if (heldItem.isEmpty()) {
playerIn.setHeldItem(hand, resultBottle);
} else if (!playerIn.inventory.addItemStackToInventory(resultBottle)) {
playerIn.dropItem(resultBottle, false);
}
}

return true;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,8 @@ public void updateTick(World world, BlockPos pos, IBlockState state, Random rand

@Override
public void neighborChanged(IBlockState state, World world, BlockPos pos, Block neighborBlock, BlockPos neighbourPos) {
if (world.isRemote) return; // Only process physical mixtures on the server
if (world.isRemote) return;

// Check if the chunk is ready to prevent chunk load leaks
if (!world.isBlockLoaded(pos)) return;

world.scheduleUpdate(pos, this, tickRate);
Expand All @@ -48,7 +47,7 @@ public void neighborChanged(IBlockState state, World world, BlockPos pos, Block

@Override
public void onBlockAdded(World world, BlockPos pos, IBlockState state) {
if (world.isRemote) return; // Only process on the server
if (world.isRemote) return;

world.scheduleUpdate(pos, this, tickRate);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.charles445.simpledifficulty.block;

import com.charles445.simpledifficulty.api.SDItems;
import net.minecraft.block.material.Material;
import net.minecraft.item.ItemStack;
import net.minecraftforge.fluids.Fluid;

public class BlockFluidSaltWater extends BlockFluidBasic {
public BlockFluidSaltWater(Fluid fluid, Material material, String iceBlock) {
super(fluid, material, iceBlock);
}

@Override
protected ItemStack getBottleResult() {
return new ItemStack(SDItems.saltWaterBottle);
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.charles445.simpledifficulty.handler;

import com.charles445.simpledifficulty.api.SDCapabilities;
import com.charles445.simpledifficulty.api.SDFluids;
import com.charles445.simpledifficulty.api.SDItems;
import com.charles445.simpledifficulty.api.SDPotions;
import com.charles445.simpledifficulty.api.config.JsonConfig;
import com.charles445.simpledifficulty.api.config.QuickConfig;
Expand All @@ -15,6 +17,7 @@
import com.charles445.simpledifficulty.network.PacketHandler;
import com.charles445.simpledifficulty.util.SoundUtil;
import com.charles445.simpledifficulty.util.internal.ThirstUtilInternal;
import net.minecraft.block.Block;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer;
Expand All @@ -25,6 +28,7 @@
import net.minecraft.item.ItemStack;
import net.minecraft.potion.PotionType;
import net.minecraft.potion.PotionUtils;
import net.minecraft.util.EnumActionResult;
import net.minecraft.util.EnumHand;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.BlockPos;
Expand All @@ -36,6 +40,7 @@
import net.minecraftforge.event.entity.player.PlayerInteractEvent;
import net.minecraftforge.event.world.BlockEvent;
import net.minecraftforge.fml.common.Loader;
import net.minecraftforge.fml.common.eventhandler.EventPriority;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;

import java.util.List;
Expand Down Expand Up @@ -135,6 +140,52 @@ public void onLivingEntityUseItemFinish(LivingEntityUseItemEvent.Finish event) {
*/
}
}

// TODO: This needs to be improved and corrected, it will be included in a future update, I'm not sure yet
// Intercept bottle interactions with mod fluid blocks
@SubscribeEvent(priority = EventPriority.HIGH)
public void onRightClickBlockBottle(PlayerInteractEvent.RightClickBlock event) {
if (event.getWorld().isRemote) {
return; // Only process on server
}

EntityPlayer player = event.getEntityPlayer();
ItemStack heldItem = player.getHeldItem(event.getHand());

// Only handle empty bottles
if (heldItem.isEmpty() || heldItem.getItem() != Items.GLASS_BOTTLE) {
return;
}

BlockPos pos = event.getPos();
IBlockState state = event.getWorld().getBlockState(pos);
Block block = state.getBlock();

// Check if clicking on mod fluid blocks
ItemStack resultBottle = null;

if (block == SDFluids.blockPurifiedWater) {
resultBottle = new ItemStack(SDItems.purifiedWaterBottle);
} else if (block == SDFluids.blockSaltWater) {
resultBottle = new ItemStack(SDItems.saltWaterBottle);
}

// If found a valid bottle result, handle it
if (resultBottle != null) {
// Cancel the vanilla interaction
event.setCanceled(true);
event.setCancellationResult(EnumActionResult.SUCCESS);

// Give the player the bottle
heldItem.shrink(1);

if (heldItem.isEmpty()) {
player.setHeldItem(event.getHand(), resultBottle);
} else if (!player.inventory.addItemStackToInventory(resultBottle)) {
player.dropItem(resultBottle, false);
}
}
}

// Both Sides
@SubscribeEvent
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.charles445.simpledifficulty.SimpleDifficulty;
import com.charles445.simpledifficulty.block.BlockFluidBasic;
import com.charles445.simpledifficulty.block.BlockFluidBasicMixable;
import com.charles445.simpledifficulty.block.BlockFluidSaltWater;
import com.charles445.simpledifficulty.fluid.FluidBasic;
import com.ferreusveritas.dynamictrees.systems.DirtHelper;
import net.minecraft.block.Block;
Expand Down Expand Up @@ -56,7 +57,7 @@ public static void registerFluidsAndFluidBlocks(RegistryEvent.Register<Block> ev

//Create Fluid Blocks
blockPurifiedWater = new BlockFluidBasicMixable(purifiedWater, Material.WATER, "purifiedwater_ice");
blockSaltWater = new BlockFluidBasic(saltWater, Material.WATER, "saltwater_ice");
blockSaltWater = new BlockFluidSaltWater(saltWater, Material.WATER, "saltwater_ice");

for(String key : fluidBlocks.keySet())
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,13 @@ public static ThirstEnumBlockPos traceWaterToDrink(EntityPlayer player)
if(traceResult==null)
return null;

if(traceResult.thirstEnum == ThirstEnum.PURIFIED && !ServerConfig.instance.getBoolean(ServerOptions.THIRST_DRINK_RAIN))
if(traceResult.thirstEnum == ThirstEnum.PURIFIED)
{
return null;
if(!ServerConfig.instance.getBoolean(ServerOptions.THIRST_DRINK_BLOCKS))
return null;

if(!ServerConfig.instance.getBoolean(ServerOptions.INFINITE_PURIFIED_WATER))
player.world.setBlockToAir(traceResult.pos);
}
else if(traceResult.thirstEnum == ThirstEnum.RAIN && !ServerConfig.instance.getBoolean(ServerOptions.THIRST_DRINK_RAIN))
{
Expand All @@ -77,8 +81,7 @@ else if(traceResult.thirstEnum == ThirstEnum.NORMAL)
if(!ServerConfig.instance.getBoolean(ServerOptions.THIRST_DRINK_BLOCKS))
return null;

if(!ServerConfig.instance.getBoolean(ServerOptions.INFINITE_PURIFIED_WATER))
player.world.setBlockToAir(traceResult.pos);
player.world.setBlockToAir(traceResult.pos);
}
else if(traceResult.thirstEnum == ThirstEnum.SALT && !ServerConfig.instance.getBoolean(ServerOptions.THIRST_DRINK_BLOCKS))
{
Expand Down