Skip to content

Commit

Permalink
Add pipes: a more economical hopper
Browse files Browse the repository at this point in the history
Pipes are cheaper than hoppers, but only have one slot and can only output items, not pull items from the world. They also can be placed facing up if enabled in the config
  • Loading branch information
KnightMiner committed Jul 1, 2018
1 parent a4508a0 commit e5c2864
Show file tree
Hide file tree
Showing 26 changed files with 924 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/main/java/knightminer/inspirations/common/Config.java
Expand Up @@ -73,6 +73,8 @@ public class Config {
public static boolean enableCarpetedTrapdoor = true;
public static boolean enableCarpetedPressurePlate = true;
public static boolean enableCollector = true;
public static boolean enablePipe = true;
public static boolean pipeUpwards = true;

// recipes
public static boolean dispensersPlaceAnvils = true;
Expand Down Expand Up @@ -265,6 +267,10 @@ public static void preInit(FMLPreInitializationEvent event) {

// collector
enableCollector = configFile.getBoolean("collector", "utility", enableCollector, "Enables the collector: extracts items from inventories or the world similar to a hopper, but can face in all 6 directions and cannot place items in inventories");

// pipe
enablePipe = configFile.getBoolean("pipe", "utility", enablePipe, "EEnables pipes: a more economical hopper that only outputs items, does not pull from inventories. Both cheaper and better for performance.");
pipeUpwards = configFile.getBoolean("upwards", "utility.pipe", pipeUpwards, "Allows pipes to output upwards. This removes a limitation on not being able to pipe items up without dropper elevators, but should be balanced alongside modded pipes.");
}

// recipes
Expand Down Expand Up @@ -719,6 +725,7 @@ private static boolean propertyEnabled(String property) {
case "bricks_button": return enableBricksButton;
case "carpeted_trapdoor": return enableCarpetedTrapdoor;
case "collector": return enableCollector;
case "pipe": return enablePipe;
case "redstone_barrel": return enableRedstoneBarrel;
case "redstone_book": return enableRedstoneBook;
case "redstone_torch_lever": return enableRedstoneTorchLever;
Expand Down
@@ -0,0 +1,19 @@
package knightminer.inspirations.library.client;

import net.minecraft.block.Block;
import net.minecraft.block.state.IBlockState;
import net.minecraft.client.renderer.block.model.ModelResourceLocation;
import net.minecraft.client.renderer.block.statemap.StateMapperBase;

public class IgnoreAllStateMapper extends StateMapperBase {

private final ModelResourceLocation location;
public IgnoreAllStateMapper(Block block) {
this.location = new ModelResourceLocation(block.getRegistryName(), "normal");
}

@Override
protected ModelResourceLocation getModelResourceLocation(IBlockState state) {
return location;
}
}
Expand Up @@ -9,8 +9,10 @@
import knightminer.inspirations.utility.block.BlockCarpetedPressurePlate;
import knightminer.inspirations.utility.block.BlockCarpetedPressurePlate.BlockCarpetedPressurePlate2;
import knightminer.inspirations.utility.tileentity.TileCollector;
import knightminer.inspirations.utility.tileentity.TilePipe;
import knightminer.inspirations.utility.block.BlockCarpetedTrapdoor;
import knightminer.inspirations.utility.block.BlockCollector;
import knightminer.inspirations.utility.block.BlockPipe;
import knightminer.inspirations.utility.block.BlockRedstoneBarrel;
import knightminer.inspirations.utility.block.BlockRedstoneTorchLever;
import knightminer.inspirations.utility.block.BlockTorchLever;
Expand Down Expand Up @@ -44,6 +46,8 @@ public class InspirationsUtility extends PulseBase {
public static Block carpetedPressurePlate1;
public static Block carpetedPressurePlate2;
public static Block collector;
public static Block pipe;
public static Item pipeItem;

@Subscribe
public void preInit(FMLPreInitializationEvent event) {
Expand Down Expand Up @@ -82,6 +86,10 @@ public void registerBlocks(Register<Block> event) {
collector = registerBlock(r, new BlockCollector(), "collector");
registerTE(TileCollector.class, "collector");
}
if(Config.enablePipe) {
pipe = registerBlock(r, new BlockPipe(), "pipe");
registerTE(TilePipe.class, "pipe");
}
}

@SubscribeEvent
Expand Down Expand Up @@ -109,6 +117,9 @@ public void registerItems(Register<Item> event) {
if(collector != null) {
registerItemBlock(r, collector);
}
if(pipe != null) {
pipeItem = registerItemBlock(r, pipe);
}
}

@Subscribe
Expand Down
Expand Up @@ -9,6 +9,7 @@

import knightminer.inspirations.common.ClientProxy;
import knightminer.inspirations.library.Util;
import knightminer.inspirations.library.client.IgnoreAllStateMapper;
import knightminer.inspirations.library.client.NameStateMapper;
import knightminer.inspirations.library.client.PropertyStateMapper;
import knightminer.inspirations.utility.block.BlockBricksButton;
Expand Down Expand Up @@ -50,12 +51,15 @@ public void registerModels(ModelRegistryEvent event) {
setModelStateMapper(InspirationsUtility.carpetedPressurePlate1, carpetedPressurePlate);
setModelStateMapper(InspirationsUtility.carpetedPressurePlate2, carpetedPressurePlate);
setModelStateMapper(InspirationsUtility.collector, new StateMap.Builder().ignore(BlockCollector.TRIGGERED).build());
// using multipart, so ignore all states to save memory
setModelStateMapper(InspirationsUtility.pipe, new IgnoreAllStateMapper(InspirationsUtility.pipe));

// blocks
registerItemModel(InspirationsUtility.torchLever);
registerItemModel(InspirationsUtility.redstoneTorchLever);
registerItemModel(InspirationsUtility.redstoneBarrel);
registerItemModel(InspirationsUtility.collector);
registerItemModel(InspirationsUtility.pipe);

// uses a property state mapper, so just redirect to the sub files for inventory
registerItemModel(InspirationsUtility.bricksButton, 0, Util.getResource("bricks_button/bricks"));
Expand Down
19 changes: 19 additions & 0 deletions src/main/java/knightminer/inspirations/utility/UtilityEvents.java
Expand Up @@ -4,6 +4,7 @@
import knightminer.inspirations.library.Util;
import knightminer.inspirations.utility.block.BlockCarpetedPressurePlate;
import net.minecraft.advancements.CriteriaTriggers;
import net.minecraft.block.BlockHopper;
import net.minecraft.block.SoundType;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.player.EntityPlayer;
Expand All @@ -21,6 +22,7 @@
import net.minecraft.world.LockCode;
import net.minecraft.world.World;
import net.minecraftforge.event.entity.player.PlayerInteractEvent.RightClickBlock;
import net.minecraftforge.fml.common.eventhandler.Event.Result;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.items.ItemHandlerHelper;

Expand Down Expand Up @@ -151,4 +153,21 @@ public static void placeCarpetOnPressurePlate(RightClickBlock event) {
event.setCanceled(true);
event.setCancellationResult(EnumActionResult.SUCCESS);
}

/**
* Makes clicking a hopper with a pipe place the pipe instead of opening the hopper's GUI
*/
@SubscribeEvent
public static void clickHopperWithPipe(RightClickBlock event) {
if(!Config.enablePipe || event.getItemStack().getItem() != InspirationsUtility.pipeItem) {
return;
}
World world = event.getWorld();
if(world.isRemote || !(world.getBlockState(event.getPos()).getBlock() instanceof BlockHopper)) {
return;
}

event.setUseBlock(Result.DENY);
event.setUseItem(Result.ALLOW);
}
}

0 comments on commit e5c2864

Please sign in to comment.