Skip to content

Commit

Permalink
Added more Constants (MinecraftForge#5323)
Browse files Browse the repository at this point in the history
  • Loading branch information
Wyn-Price authored and tterrag1098 committed Mar 15, 2019
1 parent 04a6b6c commit af4fcd7
Show file tree
Hide file tree
Showing 6 changed files with 197 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -184,20 +184,22 @@ public boolean restoreToLocation(World world, BlockPos pos, boolean force, boole
IBlockState current = getCurrentBlock();
IBlockState replaced = getReplacedBlock();

int flags = notifyNeighbors ? Constants.BlockFlags.DEFAULT : Constants.BlockFlags.SEND_TO_CLIENTS;

if (current.getBlock() != replaced.getBlock() || current.getBlock().getMetaFromState(current) != replaced.getBlock().getMetaFromState(replaced))
{
if (force)
{
world.setBlockState(pos, replaced, notifyNeighbors ? 3 : 2);
world.setBlockState(pos, replaced, flags);
}
else
{
return false;
}
}

world.setBlockState(pos, replaced, notifyNeighbors ? 3 : 2);
world.notifyBlockUpdate(pos, current, replaced, notifyNeighbors ? 3 : 2);
world.setBlockState(pos, replaced, flags);
world.notifyBlockUpdate(pos, current, replaced, flags);

TileEntity te = null;
if (getNbt() != null)
Expand Down
172 changes: 170 additions & 2 deletions src/main/java/net/minecraftforge/common/util/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,18 @@

package net.minecraftforge.common.util;

import net.minecraft.entity.ai.attributes.ModifiableAttributeInstance;

/**
* A class containing constants for magic numbers used in the minecraft codebase.
* Everything here should be checked each update, and have a comment relating to where to check it.
*/
public class Constants
{
/**
* NBT Tag type IDS, used when storing the nbt to disc, Should align with NBTBase.getId,
* NBT Tag type IDS, used when storing the nbt to disc, Should align with NBTBase.getId,
* table used in NBTBase.func_150283_g
*
*
* Main use is checking tag type in NBTTagCompound.func_150297_b(String, int)
*
*/
Expand All @@ -49,4 +51,170 @@ public static class NBT
public static final int TAG_LONG_ARRAY = 12;
public static final int TAG_ANY_NUMERIC = 99;
}

/**
* The world event IDS, used when calling {@link net.minecraft.world.World#playEvent(net.minecraft.entity.player.EntityPlayer, int, net.minecraft.util.math.BlockPos, int)}. <br>
* Can be found from {@link net.minecraft.client.renderer.RenderGlobal#playEvent}<br>
* Some of the events use the {@code data} parameter. If this is the case, an explanation of what {@code data} does is also provided
*/
public static class WorldEvents {
public static final int DISPENSER_DISPENSE_SOUND = 1000;
public static final int DISPENSER_FAIL_SOUND = 1001;
/**
* Like DISPENSER_DISPENSE_SOUND, but for items that are fired (arrows, eggs, snowballs)
*/
public static final int DISPENSER_LAUNCH_SOUND = 1002;
public static final int ENDEREYE_LAUNCH_SOUND = 1003;
public static final int FIREWORK_SHOOT_SOUND = 1004;
public static final int IRON_DOOR_OPEN_SOUND = 1005;
public static final int WOODEN_DOOR_OPEN_SOUND = 1006;
public static final int WOODEN_TRAPDOOR_OPEN_SOUND = 1007;
public static final int FENCE_GATE_OPEN_SOUND = 1008;
public static final int FIRE_EXTINGUISH_SOUND = 1009;
/**
* {@code data} is the item ID of the record you want to play
*/
public static final int PLAY_RECORD_SOUND = 1010;
public static final int IRON_DOOR_CLOSE_SOUND = 1011;
public static final int WOODEN_DOOR_CLOSE_SOUND = 1012;
public static final int WOODEN_TRAPDOOR_CLOSE_SOUND = 1013;
public static final int FENCE_GATE_CLOSE_SOUND = 1014;
public static final int GHAST_WARN_SOUND = 1015;
public static final int GHAST_SHOOT_SOUND = 1016;
public static final int ENDERDRAGON_SHOOT_SOUND = 1017;
public static final int BLAZE_SHOOT_SOUND = 1018;
public static final int ZOMBIE_ATTACK_DOOR_WOOD_SOUND = 1019;
public static final int ZOMBIE_ATTACK_DOOR_IRON_SOUND = 1020;
public static final int ZOMBIE_BREAK_DOOR_WOOD_SOUND = 1021;
public static final int WITHER_BREAK_BLOCK_SOUND = 1022;
public static final int WITHER_BREAK_BLOCK = 1023;
public static final int WITHER_SHOOT_SOUND = 1024;
public static final int BAT_TAKEOFF_SOUND = 1025;
public static final int ZOMBIE_INFECT_SOUND = 1026;
public static final int ZOMBIE_VILLAGER_CONVERTED_SOUND = 1027;
public static final int ANVIL_DESTROYED_SOUND = 1029;
public static final int ANVIL_USE_SOUND = 1030;
public static final int ANVIL_LAND_SOUND = 1031;
public static final int PORTAL_TRAVEL_SOUND = 1032;
public static final int CHORUS_FLOWER_GROW_SOUND = 1033;
public static final int CHORUS_FLOWER_DEATH_SOUND = 1034;
public static final int BREWING_STAND_BREW_SOUND = 1035;
public static final int IRON_TRAPDOOR_CLOSE_SOUND = 1036;
public static final int IRON_TRAPDOOR_OPEN_SOUND = 1037;
/**
* {@code data} is the direction of the smoke, as a grid around the dispenser as follows (with 4 being the position of the dispenser):
* <pre>
* N
* 0 | 1 | 2
* ----------
* W 3 | 4 | 5 E
* ----------
* 6 | 7 | 8
* S
* </pre>
* Setting the {@code data} to 4 will mean the particles won't spawn
*/
public static final int DISPENSER_SMOKE = 2000;

/**
* {@code data} is the {@link net.minecraft.block.Block#getStateId state id} of the block broken
*/
public static final int BREAK_BLOCK_EFFECTS = 2001;
/**
* {@code data} is the rgb color int that should be used for the potion particles
*/
public static final int SPLASH_POTION_EFFECT = 2002;
public static final int ENDER_EYE_SHATTER = 2003;
public static final int MOB_SPAWNER_PARTICLES = 2004;
/**
* {@code data} is the amount of particles to spawn. If {@code data} is 0 then there will be 15 particles spawned
*/
public static final int BONEMEAL_PARTICLES = 2005;
public static final int DRAGON_FIREBALL_HIT = 2006;
/**
* {@code data} is the rgb color int that should be used for the potion particles
*/
public static final int LINGERING_POTION_EFFECT = 2007;
public static final int GATEWAY_SPAWN_EFFECTS = 3000;
public static final int ENDERMAN_GROWL_SOUND = 3001;
}


/**
* The flags used when calling {@link net.minecraft.world.World#setBlockState}<br>
* Can be found from {@link net.minecraft.world.World#markAndNotifyBlock} and {@link net.minecraft.client.renderer.RenderGlobal#notifyBlockUpdate}<br>
* Flags can be combined with bitwise OR
*/
public static class BlockFlags {
/**
* Calls neighborChanged on surrounding blocks
*/
public static final int NOTIFY_NEIGHBORS = 0b00001;
/**
* Sends the update to the client
*/
public static final int SEND_TO_CLIENTS = 0b00010;
/**
* Stops the blocks from being marked for a render update
*/
public static final int NO_RERENDER = 0b00100;
/**
* Makes the block be re-rendered immediately, on the main thread.
* If NO_RERENDER is set, then this will be ignored
*/
public static final int RERENDER_MAIN_THREAD = 0b01000;
/**
* Disables observers from seeing this update
*/
public static final int NO_OBSERVERS = 0b10000;

public static final int DEFAULT = NOTIFY_NEIGHBORS | SEND_TO_CLIENTS;
public static final int DEFAULT_AND_RERENDER = DEFAULT | RERENDER_MAIN_THREAD;
}

/**
* The mutex bits used for AI tasks {@link net.minecraft.entity.ai.EntityAIBase#setMutexBits(int)}
* Bits can be combined with bitwise OR
*/
public static class AiMutexBits {
public static final int MOVE = 0b001;
public static final int LOOK = 0b010;
public static final int JUMP = 0b100;
}

/**
* The flags used for {@link net.minecraft.entity.Entity#getFlag(int)} and {@link net.minecraft.entity.Entity#setFlag(int, boolean)}}<br>
* Can be found by searching for the usages of getFlag
*/
public static class EntityFlags {
public static final int BURNING = 0;
public static final int SNEAKING = 1;
public static final int SPRINTING = 3;
public static final int INVISIBLE = 5;
public static final int GLOWING = 6;
public static final int ELYTRA_FLYING = 7;
}

/**
* The operation used for Attribute modifier operations, {@link net.minecraft.entity.ai.attributes.AttributeModifier#AttributeModifier(String, double, int)}<br>
* Can be found at {@link ModifiableAttributeInstance#computeValue()}<br>
* The total value starts with the base value.<br>
* Order of operations are {@link #ADD}, {@link #ADD_MULTIPLE}, {@link #MULTIPLY}
* @see <a href="https://minecraft.gamepedia.com/Attribute#Operations">Minecraft Wiki</a>
*/
public static class AttributeModifierOperation {
/**
* The modifier value is added onto the total value
*/
public static final int ADD = 0;
/**
* The modifier value is multiplied by the original base value then added onto the total value
*/
public static final int ADD_MULTIPLE = 1;
/**
* The total value is multiplied by 1 + the modifier value
*/
public static final int MULTIPLY = 2;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import net.minecraftforge.common.util.Constants;
import net.minecraftforge.event.ForgeEventFactory;

import javax.annotation.Nonnull;
Expand Down Expand Up @@ -158,7 +159,7 @@ else if (hasVerticalFlow(world, pos))
}
else
{
world.setBlockState(pos, state.withProperty(LEVEL, quantaPerBlock - expQuanta), 2);
world.setBlockState(pos, state.withProperty(LEVEL, quantaPerBlock - expQuanta), Constants.BlockFlags.SEND_TO_CLIENTS);
world.scheduleUpdate(pos, this, tickRate);
world.notifyNeighborsOfStateChange(pos, this, false);
}
Expand Down Expand Up @@ -280,7 +281,7 @@ protected void flowIntoBlock(World world, BlockPos pos, int meta)
if (meta < 0) return;
if (displaceIfPossible(world, pos))
{
world.setBlockState(pos, this.getDefaultState().withProperty(LEVEL, meta), 3);
world.setBlockState(pos, this.getDefaultState().withProperty(LEVEL, meta));
}
}

Expand Down Expand Up @@ -310,7 +311,7 @@ public int place(World world, BlockPos pos, @Nonnull FluidStack fluidStack, bool
if (doPlace)
{
FluidUtil.destroyBlockOnFluidPlacement(world, pos);
world.setBlockState(pos, this.getDefaultState(), 11);
world.setBlockState(pos, this.getDefaultState(), Constants.BlockFlags.DEFAULT_AND_RERENDER);
}
return Fluid.BUCKET_VOLUME;
}
Expand Down
25 changes: 13 additions & 12 deletions src/main/java/net/minecraftforge/fluids/BlockFluidFinite.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import net.minecraft.util.EnumFacing;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import net.minecraftforge.common.util.Constants;

import javax.annotation.Nonnull;

Expand Down Expand Up @@ -97,7 +98,7 @@ else if (quantaRemaining != prevRemaining)
changed = true;
if (quantaRemaining == 1)
{
world.setBlockState(pos, state.withProperty(LEVEL, quantaRemaining - 1), 2);
world.setBlockState(pos, state.withProperty(LEVEL, quantaRemaining - 1), Constants.BlockFlags.SEND_TO_CLIENTS);
return;
}
}
Expand Down Expand Up @@ -129,7 +130,7 @@ else if (quantaRemaining == 1)
{
if (changed)
{
world.setBlockState(pos, state.withProperty(LEVEL, quantaRemaining - 1), 2);
world.setBlockState(pos, state.withProperty(LEVEL, quantaRemaining - 1), Constants.BlockFlags.SEND_TO_CLIENTS);
}
return;
}
Expand Down Expand Up @@ -158,7 +159,7 @@ else if (quantaRemaining == 1)
}
else
{
world.setBlockState(off, getDefaultState().withProperty(LEVEL, newQuanta - 1), 2);
world.setBlockState(off, getDefaultState().withProperty(LEVEL, newQuanta - 1), Constants.BlockFlags.SEND_TO_CLIENTS);
}
world.scheduleUpdate(off, this, tickRate);
}
Expand All @@ -170,7 +171,7 @@ else if (quantaRemaining == 1)
{
++each;
}
world.setBlockState(pos, state.withProperty(LEVEL, each - 1), 2);
world.setBlockState(pos, state.withProperty(LEVEL, each - 1), Constants.BlockFlags.SEND_TO_CLIENTS);
}

public int tryToFlowVerticallyInto(World world, BlockPos pos, int amtToInput)
Expand All @@ -189,13 +190,13 @@ public int tryToFlowVerticallyInto(World world, BlockPos pos, int amtToInput)
amt += amtToInput;
if (amt > quantaPerBlock)
{
world.setBlockState(other, myState.withProperty(LEVEL, quantaPerBlock - 1), 3);
world.setBlockState(other, myState.withProperty(LEVEL, quantaPerBlock - 1));
world.scheduleUpdate(other, this, tickRate);
return amt - quantaPerBlock;
}
else if (amt > 0)
{
world.setBlockState(other, myState.withProperty(LEVEL, amt - 1), 3);
world.setBlockState(other, myState.withProperty(LEVEL, amt - 1));
world.scheduleUpdate(other, this, tickRate);
world.setBlockToAir(pos);
return 0;
Expand All @@ -209,7 +210,7 @@ else if (amt > 0)
{
if (displaceIfPossible(world, other))
{
world.setBlockState(other, myState.withProperty(LEVEL, amtToInput - 1), 3);
world.setBlockState(other, myState.withProperty(LEVEL, amtToInput - 1));
world.scheduleUpdate(other, this, tickRate);
world.setBlockToAir(pos);
return 0;
Expand All @@ -225,8 +226,8 @@ else if (amt > 0)
if (density_other < density) // then swap
{
IBlockState state = world.getBlockState(other);
world.setBlockState(other, myState.withProperty(LEVEL, amtToInput - 1), 3);
world.setBlockState(pos, state, 3);
world.setBlockState(other, myState.withProperty(LEVEL, amtToInput - 1));
world.setBlockState(pos, state);
world.scheduleUpdate(other, this, tickRate);
world.scheduleUpdate(pos, state.getBlock(), state.getBlock().tickRate(world));
return 0;
Expand All @@ -237,8 +238,8 @@ else if (amt > 0)
if (density_other > density)
{
IBlockState state = world.getBlockState(other);
world.setBlockState(other, myState.withProperty(LEVEL, amtToInput - 1), 3);
world.setBlockState(pos, state, 3);
world.setBlockState(other, myState.withProperty(LEVEL, amtToInput - 1));
world.setBlockState(pos, state);
world.scheduleUpdate(other, this, tickRate);
world.scheduleUpdate(pos, state.getBlock(), state.getBlock().tickRate(world));
return 0;
Expand Down Expand Up @@ -279,7 +280,7 @@ public int place(World world, BlockPos pos, @Nonnull FluidStack fluidStack, bool
if (doPlace)
{
FluidUtil.destroyBlockOnFluidPlacement(world, pos);
world.setBlockState(pos, getDefaultState().withProperty(LEVEL, quanta - 1), 11);
world.setBlockState(pos, getDefaultState().withProperty(LEVEL, quanta - 1), Constants.BlockFlags.DEFAULT_AND_RERENDER);
}

return closest;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import net.minecraft.util.EnumHand;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraftforge.common.util.Constants;
import net.minecraftforge.fluids.Fluid;
import net.minecraftforge.fluids.FluidRegistry;
import net.minecraftforge.fluids.FluidStack;
Expand Down Expand Up @@ -102,7 +103,7 @@ public FluidStack drain(FluidStack resource, boolean doDrain)
{
if (doDrain)
{
world.setBlockState(blockPos, Blocks.AIR.getDefaultState(), 11);
world.setBlockState(blockPos, Blocks.AIR.getDefaultState(), Constants.BlockFlags.DEFAULT_AND_RERENDER);
}
return containedStack;
}
Expand All @@ -128,7 +129,7 @@ public FluidStack drain(int maxDrain, boolean doDrain)
{
if (doDrain)
{
world.setBlockState(blockPos, Blocks.AIR.getDefaultState(), 11);
world.setBlockState(blockPos, Blocks.AIR.getDefaultState(), Constants.BlockFlags.DEFAULT_AND_RERENDER);
}
return containedStack;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import net.minecraft.block.Block;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraftforge.common.util.Constants;
import net.minecraftforge.fluids.Fluid;
import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.fluids.FluidUtil;
Expand Down Expand Up @@ -56,7 +57,7 @@ public int fill(FluidStack resource, boolean doFill)
if (doFill)
{
FluidUtil.destroyBlockOnFluidPlacement(world, blockPos);
world.setBlockState(blockPos, block.getDefaultState(), 11);
world.setBlockState(blockPos, block.getDefaultState(), Constants.BlockFlags.DEFAULT_AND_RERENDER);
}
return Fluid.BUCKET_VOLUME;
}
Expand Down

0 comments on commit af4fcd7

Please sign in to comment.