Skip to content

Commit

Permalink
Work on particles + paint + rotation + sound.
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexIIL committed Jul 10, 2016
1 parent d657dad commit 6426308
Show file tree
Hide file tree
Showing 24 changed files with 826 additions and 242 deletions.
391 changes: 373 additions & 18 deletions LICENSE-NEW

Large diffs are not rendered by default.

75 changes: 0 additions & 75 deletions common/buildcraft/api/blocks/CustomRotationHelper.java

This file was deleted.

11 changes: 0 additions & 11 deletions common/buildcraft/api/blocks/ICustomRotationHandler.java

This file was deleted.

93 changes: 0 additions & 93 deletions common/buildcraft/api/core/BCDebugging.java

This file was deleted.

28 changes: 21 additions & 7 deletions common/buildcraft/core/item/ItemPaintbrush_BC8.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

import org.apache.commons.lang3.StringUtils;

import net.minecraft.block.Block;
import net.minecraft.block.state.IBlockState;
import net.minecraft.client.renderer.block.model.ModelResourceLocation;
import net.minecraft.creativetab.CreativeTabs;
Expand All @@ -21,13 +20,18 @@
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumHand;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Vec3d;
import net.minecraft.util.text.translation.I18n;
import net.minecraft.world.World;

import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;

import buildcraft.api.blocks.CustomPaintHelper;
import buildcraft.lib.item.ItemBC_Neptune;
import buildcraft.lib.misc.ParticleUtil;
import buildcraft.lib.misc.SoundUtil;
import buildcraft.lib.misc.VecUtil;

import gnu.trove.map.hash.TIntObjectHashMap;

Expand Down Expand Up @@ -60,7 +64,8 @@ public void addModelVariants(TIntObjectHashMap<ModelResourceLocation> variants)
@Override
public EnumActionResult onItemUse(ItemStack stack, EntityPlayer player, World world, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
Brush brush = new Brush(stack);
if (brush.useOnBlock(world, pos, world.getBlockState(pos), facing)) {
Vec3d hitPos = VecUtil.add(new Vec3d(hitX, hitY, hitZ), pos);
if (brush.useOnBlock(world, pos, world.getBlockState(pos), hitPos, facing)) {
ItemStack newStack = brush.save(stack);
if (newStack != null) {
player.setHeldItem(hand, newStack);
Expand Down Expand Up @@ -165,12 +170,21 @@ public int getMeta() {
return (usesLeft <= 0 || colour == null) ? 0 : colour.getMetadata() + 1;
}

public boolean useOnBlock(World world, BlockPos pos, IBlockState state, EnumFacing side) {
if (colour == null || usesLeft <= 0) return false;
Block block = state.getBlock();
if (block.recolorBlock(world, pos, side, colour)) {
public boolean useOnBlock(World world, BlockPos pos, IBlockState state, Vec3d hitPos, EnumFacing side) {
if (colour != null && usesLeft <= 0) {
return false;
}

EnumActionResult result = CustomPaintHelper.INSTANCE.attemptPaintBlock(world, pos, state, hitPos, side, colour);

if (result == EnumActionResult.SUCCESS) {
ParticleUtil.showChangeColour(world, hitPos, colour);
SoundUtil.playChangeColour(world, pos, colour);
usesLeft--;
if (usesLeft <= 0) colour = null;
if (usesLeft <= 0) {
colour = null;
usesLeft = 0;
}
return true;
}
return false;
Expand Down
9 changes: 6 additions & 3 deletions common/buildcraft/core/item/ItemWrench_Neptune.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import buildcraft.api.blocks.CustomRotationHelper;
import buildcraft.api.tools.IToolWrench;
import buildcraft.lib.item.ItemBC_Neptune;
import buildcraft.lib.misc.SoundUtil;

public class ItemWrench_Neptune extends ItemBC_Neptune implements IToolWrench {
public ItemWrench_Neptune(String id) {
Expand All @@ -36,14 +37,16 @@ public void wrenchUsed(EntityPlayer player, EnumHand hand, ItemStack wrench, Ray

@Override
public EnumActionResult onItemUse(ItemStack stack, EntityPlayer player, World world, BlockPos pos, EnumHand hand, EnumFacing side, float hitX, float hitY, float hitZ) {
if (world.isRemote) {
return EnumActionResult.PASS;
}
// FIXME: Disabled world check as it doesn't allow us to swing the player's arm!
// if (world.isRemote) {
// return EnumActionResult.PASS;
// }
IBlockState state = world.getBlockState(pos);
state = state.getActualState(world, pos);
EnumActionResult result = CustomRotationHelper.INSTANCE.attemptRotateBlock(world, pos, state, side);
if (result == EnumActionResult.SUCCESS) {
wrenchUsed(player, hand, stack, new RayTraceResult(new Vec3d(hitX, hitY, hitZ), side, pos));
SoundUtil.playSlideSound(world, pos, state);
}
return result;
}
Expand Down
4 changes: 0 additions & 4 deletions common/buildcraft/core/marker/PathConnection.java
Original file line number Diff line number Diff line change
Expand Up @@ -217,10 +217,6 @@ public void reverseDirection() {
@Override
@SideOnly(Side.CLIENT)
public void renderInWorld() {
if(positions.isEmpty()) {
return;
}

BlockPos last = null;
for (BlockPos p : positions) {
if (last == null) {
Expand Down
6 changes: 4 additions & 2 deletions common/buildcraft/lib/BCLib.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

import buildcraft.api.BCModules;
import buildcraft.api.core.BuildCraftAPI;
import buildcraft.lib.block.VanillaPaintHandlers;
import buildcraft.lib.block.VanillaRotationHandlers;
import buildcraft.lib.bpt.vanilla.VanillaBlueprints;
import buildcraft.lib.item.ItemManager;
Expand Down Expand Up @@ -54,9 +55,10 @@ public void preInit(FMLPreInitializationEvent evt) {
public void init(FMLInitializationEvent evt) {
LibProxy.getProxy().fmlInit();

VanillaRotationHandlers.fmlInit();
VanillaListHandlers.fmlInit();
VanillaBlueprints.fmlInit();
VanillaListHandlers.fmlInit();
VanillaPaintHandlers.fmlInit();
VanillaRotationHandlers.fmlInit();

ItemManager.fmlInit();

Expand Down
7 changes: 3 additions & 4 deletions common/buildcraft/lib/BCMessageHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,8 @@
import buildcraft.lib.library.network.MessageLibraryDBIndex;
import buildcraft.lib.library.network.MessageLibraryRequest;
import buildcraft.lib.library.network.MessageLibraryTransferEntry;
import buildcraft.lib.net.MessageCommand;
import buildcraft.lib.net.MessageMarker;
import buildcraft.lib.net.MessageUpdateTile;
import buildcraft.lib.net.MessageWidget;
import buildcraft.lib.net.*;
import buildcraft.lib.particle.MessageParticleVanilla;

public enum BCMessageHandler {
INSTANCE;
Expand All @@ -50,6 +48,7 @@ public static void fmlPreInit() {
addMessageType(MessageLibraryTransferEntry.class, MessageLibraryTransferEntry.Handler.INSTANCE, Side.CLIENT, Side.SERVER);
addMessageType(MessageLibraryRequest.class, MessageLibraryRequest.Handler.INSTANCE, Side.CLIENT, Side.SERVER);
addMessageType(MessageLibraryDBIndex.class, MessageLibraryDBIndex.Handler.INSTANCE, Side.CLIENT, Side.SERVER);
addMessageType(MessageParticleVanilla.class, MessageParticleVanilla.Handler.INSTANCE, Side.CLIENT);
}

public static void fmlPostInit() {
Expand Down
55 changes: 55 additions & 0 deletions common/buildcraft/lib/block/VanillaPaintHandlers.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package buildcraft.lib.block;

import net.minecraft.block.Block;
import net.minecraft.block.BlockColored;
import net.minecraft.block.BlockStainedGlass;
import net.minecraft.block.BlockStainedGlassPane;
import net.minecraft.block.properties.IProperty;
import net.minecraft.block.state.IBlockState;
import net.minecraft.init.Blocks;
import net.minecraft.item.EnumDyeColor;
import net.minecraft.util.EnumActionResult;

import buildcraft.api.blocks.CustomPaintHelper;
import buildcraft.api.blocks.ICustomPaintHandler;

public class VanillaPaintHandlers {

public static void fmlInit() {
registerDoubleTypedHandler(Blocks.GLASS, Blocks.STAINED_GLASS, BlockStainedGlass.COLOR);
registerDoubleTypedHandler(Blocks.GLASS_PANE, Blocks.STAINED_GLASS_PANE, BlockStainedGlassPane.COLOR);
registerDoubleTypedHandler(Blocks.HARDENED_CLAY, Blocks.STAINED_HARDENED_CLAY, BlockColored.COLOR);
}

private static void registerDoubleTypedHandler(Block clear, Block dyed, IProperty<EnumDyeColor> colourProp) {
ICustomPaintHandler handler = createDoubleTypedPainter(clear, dyed, colourProp);
CustomPaintHelper.INSTANCE.registerHandler(clear, handler);
CustomPaintHelper.INSTANCE.registerHandler(dyed, handler);
}

public static ICustomPaintHandler createDoubleTypedPainter(Block clear, Block dyed, IProperty<EnumDyeColor> colourProp) {
return (world, pos, state, hitPos, hitSide, to) -> {
if (state.getBlock() == clear) {
// We are currently clear
if (to == null) {
return EnumActionResult.FAIL;
}
IBlockState painted = dyed.getDefaultState().withProperty(colourProp, to);
world.setBlockState(pos, painted);
return EnumActionResult.SUCCESS;
} else if (state.getBlock() == dyed) {
if (to == state.getValue(colourProp)) {
return EnumActionResult.FAIL;
}
if (to == null) {
state = clear.getDefaultState();
} else {
state = state.withProperty(colourProp, to);
}
world.setBlockState(pos, state);
return EnumActionResult.SUCCESS;
}
return EnumActionResult.PASS;
};
}
}
1 change: 1 addition & 0 deletions common/buildcraft/lib/block/VanillaRotationHandlers.java
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ private static EnumActionResult rotatePiston(World world, BlockPos pos, IBlockSt
EnumFacing currentSide = state.getValue(BlockDirectional.FACING);
int ord = getOrdinal(currentSide, ALL_SIDES) + 1;
world.setBlockState(pos, state.withProperty(BlockDirectional.FACING, ALL_SIDES[ord % 6]));
return EnumActionResult.SUCCESS;
}
return EnumActionResult.PASS;
}
Expand Down
Loading

0 comments on commit 6426308

Please sign in to comment.