Skip to content

Commit

Permalink
Fix dedicated server issues
Browse files Browse the repository at this point in the history
  • Loading branch information
JoshieGemFinder committed Aug 14, 2024
1 parent b4681fe commit 5ae4016
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ public IBlockState withMirror(IBlockState state, Mirror mirrorIn)

@Override
public boolean eventReceived(IBlockState state, World world, BlockPos pos, int id, int param) {
if(id == 9002) {
if(id == 92) {
EnumFacing facing = world.getBlockState(pos).getValue(FACING);
shootParticles(facing, world, pos);
return true;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
package com.joshiegemfinder.betweenlandsredstone.blocks;

import java.util.Random;

import com.joshiegemfinder.betweenlandsredstone.BetweenlandsRedstone;
import com.joshiegemfinder.betweenlandsredstone.ModBlocks;

import net.minecraft.block.BlockObserver;
import net.minecraft.block.state.IBlockState;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;

public class BlockScabystObserver extends BlockObserver {

Expand All @@ -15,7 +21,32 @@ public BlockScabystObserver(String name) {

this.setUnlocalizedName(name);
this.setRegistryName(new ResourceLocation(BetweenlandsRedstone.MODID, name));
if(this.getDefaultState().getBlock() != this) {
this.setDefaultState(this.getBlockState().getBaseState().withProperty(FACING, EnumFacing.SOUTH).withProperty(POWERED, Boolean.valueOf(false)));
}
ModBlocks.BLOCKS.add(this);
}

@Override
public void updateTick(World worldIn, BlockPos pos, IBlockState state, Random rand)
{
super.updateTick(worldIn, pos, state, rand);

// Neighbour updates could've changed the block
IBlockState newState = worldIn.getBlockState(pos);
if(newState.getBlock() == this)
worldIn.addBlockEvent(pos, this, 93, newState.getValue(POWERED).booleanValue() ? 1 : 0);
}

// HACK: For no apparent reason, scabyst observers won't render updates on dedicated servers, so I had to hack together an event to manually inform the client.
@SuppressWarnings("deprecation")
@Override
public boolean eventReceived(IBlockState state, World worldIn, BlockPos pos, int id, int param) {
if(id == 93) {
if(!worldIn.isRemote) return true;
worldIn.setBlockState(pos, worldIn.getBlockState(pos).withProperty(POWERED, param != 0), 2);
return true;
}
return super.eventReceived(state, worldIn, pos, id, param);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -326,8 +326,8 @@ public void tryToCraft() {
this.world.setBlockState(pos, newState, 3);

if(playEjectParticles && !world.isRemote) {
this.world.addBlockEvent(pos, this.getBlockType(), 9002, 0);
// this.world.getMinecraftServer().getPlayerList().sendToAllNearExcept((EntityPlayer)null, (double)pos.getX(), (double)pos.getY(), (double)pos.getZ(), 64.0D, this.world.provider.getDimension(), new SPacketBlockAction(pos, this.getBlockType(), 9002, 0));
this.world.addBlockEvent(pos, this.getBlockType(), 92, 0);
// this.world.getMinecraftServer().getPlayerList().sendToAllNearExcept((EntityPlayer)null, (double)pos.getX(), (double)pos.getY(), (double)pos.getZ(), 64.0D, this.world.provider.getDimension(), new SPacketBlockAction(pos, this.getBlockType(), 92, 0));
}

this.onCraftMatrixChanged();
Expand Down

0 comments on commit 5ae4016

Please sign in to comment.