Skip to content

Commit

Permalink
Charset 0.4.0-pre7 I should really not make builds at night again edi…
Browse files Browse the repository at this point in the history
…tion
  • Loading branch information
asiekierka committed Jan 6, 2017
1 parent 0c00b14 commit f16965e
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 15 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Expand Up @@ -18,7 +18,7 @@ apply plugin: 'com.github.johnrengelman.shadow'
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8

version = "0.4.0-pre6"
version = "0.4.0-pre7"
group = "pl.asie.charset"
archivesBaseName = "Charset"

Expand Down
2 changes: 0 additions & 2 deletions changelog/0.4.0-pre6.txt
@@ -1,4 +1,2 @@
* [Carts] Add option to set the minimum minecart item stack size
* [Carts] Fix TrackCombiner not working correctly in survival mode
* [Decoration] Fix posters being a massive lagfest
* [Lib] Fix broken modded wood detection
2 changes: 2 additions & 0 deletions changelog/0.4.0-pre7.txt
@@ -0,0 +1,2 @@
* [Carts] Add option to set the minimum minecart item stack size
* [Carts] Fix TrackCombiner not working correctly in survival mode
3 changes: 3 additions & 0 deletions src/main/java/pl/asie/charset/carts/BlockRailCharset.java
@@ -1,6 +1,7 @@
package pl.asie.charset.carts;

import net.minecraft.block.BlockRailBase;
import net.minecraft.block.SoundType;
import net.minecraft.block.properties.IProperty;
import net.minecraft.block.properties.PropertyEnum;
import net.minecraft.block.state.BlockStateContainer;
Expand All @@ -21,6 +22,8 @@ public class BlockRailCharset extends BlockRailBase {
protected BlockRailCharset() {
super(false);
setCreativeTab(ModCharsetLib.CREATIVE_TAB);
setHardness(0.7F);
setSoundType(SoundType.METAL);
setUnlocalizedName("charset.rail_charset");
}

Expand Down
16 changes: 16 additions & 0 deletions src/main/java/pl/asie/charset/carts/ModCharsetCarts.java
Expand Up @@ -24,6 +24,8 @@
import net.minecraft.entity.Entity;
import net.minecraft.entity.item.EntityMinecart;
import net.minecraft.init.Blocks;
import net.minecraft.item.Item;
import net.minecraft.item.ItemMinecart;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ResourceLocation;
import net.minecraft.world.World;
Expand All @@ -33,6 +35,7 @@
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.SidedProxy;
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPostInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.common.registry.EntityRegistry;
Expand All @@ -59,6 +62,7 @@ public class ModCharsetCarts {
public static ModCharsetCarts instance;
public static TrackCombiner combiner;
public static Logger logger;
public static int minecartStackSize;

public static BlockRailCharset blockRailCross;

Expand All @@ -77,6 +81,7 @@ private void register(Class<? extends EntityMinecart> minecart, String name, Cla
public void preInit(FMLPreInitializationEvent event) {
logger = LogManager.getLogger(ModCharsetCarts.MODID);
config = new Configuration(ModCharsetLib.instance.getConfigFile("carts.cfg"));
minecartStackSize = config.getInt("minecartStackSize", "tweaks", 4, 1, 64, "Sets the minimum stack size for all minecarts.");

ModCharsetLib.proxy.registerBlock(blockRailCross = new BlockRailCharset(), "rail_charset");
ModCharsetLib.proxy.registerItemModel(blockRailCross, 0, "charsetcarts:rail_charset");
Expand Down Expand Up @@ -111,13 +116,24 @@ public void init(FMLInitializationEvent event) {
if (combiner != null) {
MinecraftForge.EVENT_BUS.register(combiner);

// TODO: This needs a redesign... Possibly move the Combiner to Lib.
combiner.register(Blocks.RAIL, blockRailCross.getDefaultState(), new ItemStack(Blocks.RAIL));
combiner.register(Blocks.RAIL, blockRailCross.getDefaultState().withProperty(BlockRailCharset.DIRECTION, BlockRailBase.EnumRailDirection.EAST_WEST), new ItemStack(Blocks.RAIL));
registerCombinerRecipeForDirs(Blocks.RAIL, BlockRail.SHAPE, Blocks.DETECTOR_RAIL, BlockRailDetector.SHAPE, new ItemStack(Blocks.STONE_PRESSURE_PLATE));
} else {
GameRegistry.addShapedRecipe(new ItemStack(blockRailCross, 2), " r ", "r r", " r ", 'r', new ItemStack(Blocks.RAIL));
}
}

@Mod.EventHandler
public void postInit(FMLPostInitializationEvent event) {
for (Item item : Item.REGISTRY) {
if (item instanceof ItemMinecart && item.getItemStackLimit() < minecartStackSize) {
item.setMaxStackSize(minecartStackSize);
}
}
}

@SubscribeEvent
public void onEntitySpawn(EntityJoinWorldEvent event) {
Class<? extends Entity> classy = event.getEntity().getClass();
Expand Down
34 changes: 34 additions & 0 deletions src/main/java/pl/asie/charset/carts/TrackCombiner.java
Expand Up @@ -9,8 +9,10 @@
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.World;
import net.minecraftforge.event.entity.player.PlayerInteractEvent;
import net.minecraftforge.event.world.BlockEvent;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import org.apache.commons.lang3.tuple.Pair;
import pl.asie.charset.lib.ModCharsetLib;
import pl.asie.charset.lib.utils.ItemUtils;

import java.util.HashMap;
Expand Down Expand Up @@ -45,6 +47,38 @@ public void onRightClickBlock(PlayerInteractEvent.RightClickBlock event) {
}
}

@SubscribeEvent
public void onBlockHarvest(BlockEvent.HarvestDropsEvent event) {
if (event.getState() == null) {
return;
}

World world = event.getWorld();
BlockPos pos = event.getPos();

// WORKAROUND: Some mods seem to like event.getDrops() being null.
// This is not what Forge does.
if (event.getDrops() == null) {
ModCharsetLib.logger.error("Block " + event.getState().getBlock().getRegistryName() + " provides a null getDrops() list, against Forge's original method behaviour! This is a bug in the mod providing it!");
return;
}

IBlockState state = event.getState();
if (transformInv.containsKey(state)) {
event.getDrops().clear();
IBlockState oldState = world.getBlockState(pos);
world.setBlockState(pos, state, 4); // This is just for internal use; no block updates or resend
while (transformInv.containsKey(state)) {
Pair<ItemStack, IBlockState> pair = transformInv.get(state);
event.getDrops().add(pair.getLeft().copy());
state = pair.getRight();
world.setBlockState(pos, state, 4);
}
event.getDrops().addAll(state.getBlock().getDrops(world, pos, state, event.getFortuneLevel()));
world.setBlockState(pos, oldState, 2);
}
}

@SubscribeEvent
public void onLeftClickBlock(PlayerInteractEvent.LeftClickBlock event) {
World world = event.getWorld();
Expand Down
Expand Up @@ -107,18 +107,7 @@ protected void keyTyped(char key, int par2) throws IOException {
char my_key = ("" + key).toLowerCase(Locale.ROOT).charAt(0);
int action = -1;
int arg = 0;
// 'x' clears items out of the way. Fill inv, then bag (and make slurp
// sound). [XXX TODO -- Doing this server-friendly'd require a packet or
// something]
// 'z' in crafting area, balance items out. Then fill in with rest of
// inventory.
// 'c' cycle layout, based on outer edge:
// - Full: rotate
// - In a '\' corner: spread left/right
// - In a '/' corner: spread up/down
// - A line along a side: spread to the other side, skipping the middle.
// - Two touching: fill the circumerfence, alternating.
// - middle of a side: spread across center

if (my_key == ModCharsetCrafting.pocketActions.charAt(0) /* x */) {
action = PacketPTAction.CLEAR;
} else if (my_key == ModCharsetCrafting.pocketActions.charAt(1) /* c */) {
Expand Down

0 comments on commit f16965e

Please sign in to comment.