Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add railcraft compat for the two tracks #179

Draft
wants to merge 1 commit into
base: 1.12
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ repositories {
name = "Modmuss50"
url = "http://maven.modmuss50.me/"
}
flatDir {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why this? I do not see the railcraft jar, and I would be a lot happier using maven, even if it was from curse's maven endpoint.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

railcraft does not have a proper maven set up now unfortunately. i might see if railcraft can use bintray or something similar.

dirs 'lib'
}
}


Expand All @@ -67,6 +70,10 @@ dependencies {
transitive = false
}
deobfCompile 'net.industrial-craft:industrialcraft-2:2.8.104-ex112'

// lib folder
compile name: "railcraft-12.0.0-beta-4-api"
provided name: "railcraft-12.0.0-beta-4-api"
}

processResources{
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/vswe/stevescarts/SCConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public class SCConfig {
public static boolean enableEaster = true;
public static boolean enableHalloween = true;
public static boolean enableChristmas = true;
public static boolean railcraftCompat = true;

private static Multimap<String,String> ironTierRepair;
private static Multimap<String,String> diamondTierRepair;
Expand Down Expand Up @@ -83,6 +84,9 @@ public void sync() {
enableEaster = config.getBoolean("Enable Easter", "Events", true, "If the easter event can occur");
enableHalloween = config.getBoolean("Enable Halloween", "Events", true, "If the halloween event can occur");
enableChristmas = config.getBoolean("Enable Christmas", "Events", true, "If the christmas event can occur");

railcraftCompat = config.getBoolean("Enable Railcraft Compatibility", "Compatibility", true, "If Railcraft compatibility content would be "
+ "added when Railcraft is present");
save();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,4 +194,6 @@ public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, En
public void refreshState(World world, BlockPos pos, IBlockState state, boolean flag) {
new BlockRailBase.Rail(world, pos, state).place(flag, false);
}


}
26 changes: 24 additions & 2 deletions src/main/java/vswe/stevescarts/blocks/ModBlocks.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
package vswe.stevescarts.blocks;

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.StateMap;
import net.minecraft.item.Item;
import net.minecraft.item.ItemBlock;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraftforge.client.event.ModelRegistryEvent;
import net.minecraftforge.client.model.ModelLoader;
import net.minecraftforge.event.RegistryEvent;
Expand All @@ -20,6 +23,7 @@
import vswe.stevescarts.Constants;
import vswe.stevescarts.StevesCarts;
import vswe.stevescarts.blocks.tileentities.*;
import vswe.stevescarts.compat.railcraft.RailcraftHook;

import java.util.ArrayList;
import java.util.List;
Expand All @@ -34,8 +38,22 @@ public enum ModBlocks {
MODULE_TOGGLER("BlockActivator", BlockActivator.class, TileEntityActivator.class, "activator"),
DETECTOR_UNIT("BlockDetector", BlockDetector.class, TileEntityDetector.class, "detector"),
UPGRADE("upgrade", BlockUpgrade.class, TileEntityUpgrade.class, "upgrade"),
JUNCTION("BlockJunction", BlockRailJunction.class),
ADVANCED_DETECTOR("BlockAdvDetector", BlockRailAdvDetector.class),
JUNCTION("BlockJunction", BlockRailJunction.class) {
@Override
public boolean isAt(World world, BlockPos pos, IBlockState state) {
if (super.isAt(world, pos, state))
return true;
return RailcraftHook.getInstance().isJunction(world, pos, state);
}
},
ADVANCED_DETECTOR("BlockAdvDetector", BlockRailAdvDetector.class) {
@Override
public boolean isAt(World world, BlockPos pos, IBlockState state) {
if (super.isAt(world, pos, state))
return true;
return RailcraftHook.getInstance().isAdvDetector(world, pos, state);
}
},
STORAGE("BlockMetalStorage", BlockMetalStorage.class);

public static final List<ItemBlock> ITEM_BLOCKS = new ArrayList<>();
Expand Down Expand Up @@ -132,6 +150,10 @@ public Block getBlock() {
return block;
}

public boolean isAt(World world, BlockPos pos, IBlockState state) {
return state.getBlock() == block;
}

public interface ISubtypeItemBlockModelDefinition {
/**
* Returns the amount of subtypes
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
package vswe.stevescarts.compat.railcraft;

import mods.railcraft.api.core.IRailcraftModule;
import mods.railcraft.api.core.RailcraftModule;
import mods.railcraft.api.tracks.TrackRegistry;
import net.minecraft.init.Blocks;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.Ingredient;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.common.crafting.CraftingHelper;
import net.minecraftforge.fml.common.registry.ForgeRegistries;
import net.minecraftforge.fml.common.registry.GameRegistry;
import vswe.stevescarts.Constants;
import vswe.stevescarts.SCConfig;
import vswe.stevescarts.blocks.BlockRailAdvDetector;
import vswe.stevescarts.blocks.BlockRailJunction;
import vswe.stevescarts.blocks.ModBlocks;
import vswe.stevescarts.compat.railcraft.kit.KitAdvDetector;
import vswe.stevescarts.compat.railcraft.kit.KitJunction;

@RailcraftModule(value = Constants.MOD_ID + ":railcraft_compat", description = "Steves Carts Reborn Railcraft compatibility")
public class CompatRailcraft implements IRailcraftModule {

public static final String MOD_ID = "railcraft";
private static final ModuleEventHandler DISABLED = new ModuleEventHandler() {
};

@Override
public void checkPrerequisites() {
}

@Override
public ModuleEventHandler getModuleEventHandler(boolean enabled) {
return !SCConfig.railcraftCompat ? DISABLED : new ModuleEventHandler() {
@Override
public void construction() {
RailcraftHook.init();
}

@Override
public void preInit() {
TrackRegistry.TRACK_KIT.register(KitAdvDetector.KIT);
TrackRegistry.TRACK_KIT.register(KitJunction.KIT);
}

@Override
public void init() {
KitAdvDetector.setAdvDetector((BlockRailAdvDetector) ModBlocks.ADVANCED_DETECTOR.getBlock());
Item partsItem = ForgeRegistries.ITEMS.getValue(new ResourceLocation(MOD_ID, "track_parts"));
Ingredient parts = CraftingHelper.getIngredient(partsItem == null ? "ingotIron" : new ItemStack(partsItem));
Ingredient plank = CraftingHelper.getIngredient("plankWood");
Ingredient redstone = CraftingHelper.getIngredient("dustRedstone");
Ingredient stonePlate = CraftingHelper.getIngredient(Blocks.STONE_PRESSURE_PLATE);

ItemStack advDetectorKit = KitAdvDetector.KIT.getTrackKitItem();
GameRegistry.addShapelessRecipe(new ResourceLocation(Constants.MOD_ID, "advanced_detector_track_kit"), null, advDetectorKit, parts,
plank, redstone, stonePlate, stonePlate);

ItemStack junctionKit = KitJunction.KIT.getTrackKitItem();
GameRegistry.addShapelessRecipe(new ResourceLocation(Constants.MOD_ID, "junction_track_kit"), null, junctionKit, parts, plank,
redstone, redstone, redstone);
}

@Override
public void postInit() {

}
};
}
}
60 changes: 60 additions & 0 deletions src/main/java/vswe/stevescarts/compat/railcraft/RailcraftHook.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package vswe.stevescarts.compat.railcraft;

import mods.railcraft.api.tracks.IOutfittedTrackTile;
import mods.railcraft.api.tracks.TrackToolsAPI;
import net.minecraft.block.state.IBlockState;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import vswe.stevescarts.compat.railcraft.kit.KitAdvDetector;

public class RailcraftHook {

private static RailcraftHook instance = new RailcraftHook();

public static RailcraftHook getInstance() {
return instance;
}

static void init() {
instance = new Exist();
}

RailcraftHook() {
}

public boolean isAdvDetector(World world, BlockPos pos, IBlockState state) {
return false;
}

public boolean isJunction(World world, BlockPos pos, IBlockState state) {
return false;
}

static final class Exist extends RailcraftHook {

@Override
public boolean isAdvDetector(World world, BlockPos pos, IBlockState state) {
if (state.getBlock() != TrackToolsAPI.blockTrackOutfitted) {
return false;
}
TileEntity te = world.getTileEntity(pos);
if (!(te instanceof IOutfittedTrackTile)) {
return false;
}
return ((IOutfittedTrackTile) te).getTrackKitInstance().getTrackKit() == KitAdvDetector.KIT;
}

@Override
public boolean isJunction(World world, BlockPos pos, IBlockState state) {
if (state.getBlock() != TrackToolsAPI.blockTrackOutfitted) {
return false;
}
TileEntity te = world.getTileEntity(pos);
if (!(te instanceof IOutfittedTrackTile)) {
return false;
}
return ((IOutfittedTrackTile) te).getTrackKitInstance().getTrackKit() == KitAdvDetector.KIT;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package vswe.stevescarts.compat.railcraft.kit;

import mods.railcraft.api.tracks.TrackKit;
import mods.railcraft.api.tracks.TrackKitInstance;
import net.minecraft.entity.item.EntityMinecart;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumHand;
import net.minecraft.util.ResourceLocation;
import vswe.stevescarts.Constants;
import vswe.stevescarts.blocks.BlockRailAdvDetector;

public class KitAdvDetector extends TrackKitInstance {

public static final TrackKit KIT = new TrackKit.Builder(new ResourceLocation(Constants.MOD_ID, "advanced_detector"), KitAdvDetector.class)
.setAllowedOnSlopes(false)
.setRenderStates(1)
.build();
private static BlockRailAdvDetector block;

@Override
public TrackKit getTrackKit() {
return KIT;
}

public static void setAdvDetector(BlockRailAdvDetector detector) {
block = detector;
}

public KitAdvDetector() {
}

@Override
public void onMinecartPass(EntityMinecart cart) {
block.onMinecartPass(theWorldAsserted(), cart, getPos());
}

// TODO canConnectRedstone not accomplishable


@Override public boolean blockActivated(EntityPlayer player, EnumHand hand) {
return block.onBlockActivated(theWorldAsserted(), getPos(), theWorldAsserted().getBlockState(getPos()), player, hand, EnumFacing.UP, 0, 0, 0);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package vswe.stevescarts.compat.railcraft.kit;

import mods.railcraft.api.tracks.TrackKit;
import mods.railcraft.api.tracks.TrackKitInstance;
import net.minecraft.block.BlockRailBase;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.item.EntityMinecart;
import net.minecraft.util.ResourceLocation;
import vswe.stevescarts.Constants;
import vswe.stevescarts.blocks.BlockRailJunction;
import vswe.stevescarts.entitys.EntityMinecartModular;

public class KitJunction extends TrackKitInstance {

public static final TrackKit KIT = new TrackKit.Builder(new ResourceLocation(Constants.MOD_ID, "junction"), KitJunction.class)
.setAllowedOnSlopes(false)
.setRenderer(TrackKit.Renderer.UNIFIED)
.setRenderStates(6) //TODO
.build();

@Override
public TrackKit getTrackKit() {
return KIT;
}

public KitJunction() {
}

@Override
public BlockRailBase.EnumRailDirection getRailDirection(IBlockState state, EntityMinecart cart) {
if (cart instanceof EntityMinecartModular) {
final EntityMinecartModular modularCart = (EntityMinecartModular) cart;
BlockRailBase.EnumRailDirection direction = modularCart.getRailDirection(getPos());
if (direction != null) {
return direction;
}
}
return super.getRailDirection(state, cart);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import net.minecraft.network.datasync.DataSerializer;
import net.minecraft.network.datasync.DataSerializers;

import java.util.Arrays;

public class CartDataSerializers {

public static void init() {
Expand All @@ -29,7 +31,7 @@ public DataParameter<int[]> createKey(int id) {

@Override
public int[] copyValue(int[] p_192717_1_) {
return p_192717_1_;
return p_192717_1_.clone();
}
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -670,10 +670,10 @@ public void moveMinecartOnRail(BlockPos pos) {
EnumRailDirection railDirection = ((BlockRailBase) blockState.getBlock()).getRailDirection(world, pos, blockState, this);
cornerFlip = ((railDirection == EnumRailDirection.SOUTH_EAST || railDirection == EnumRailDirection.SOUTH_WEST) && motionX < 0.0)
|| ((railDirection == EnumRailDirection.NORTH_EAST || railDirection == EnumRailDirection.NORTH_WEST) && motionX > 0.0);
if (blockState.getBlock() != ModBlocks.ADVANCED_DETECTOR.getBlock() && isDisabled()) {
if (ModBlocks.ADVANCED_DETECTOR.isAt(world, pos, blockState) && isDisabled()) {
releaseCart();
}
boolean canBeDisabled = blockState.getBlock() == ModBlocks.ADVANCED_DETECTOR.getBlock()
boolean canBeDisabled = ModBlocks.ADVANCED_DETECTOR.isAt(world, pos, blockState)
&& (stateBelow.getBlock() != ModBlocks.DETECTOR_UNIT.getBlock() || !DetectorType.getTypeFromSate(stateBelow).canInteractWithCart() || DetectorType.getTypeFromSate(stateBelow).shouldStopCart());
final boolean forceUnDisable = wasDisabled && disabledPos != null && disabledPos.equals(pos);
if (!forceUnDisable && wasDisabled) {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/vswe/stevescarts/helpers/DetectorType.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public void deactivate(TileEntityDetector detector) {
private void update(TileEntityDetector detector, boolean flag) {
BlockPos posUp = detector.getPos().up();
IBlockState stateUp = detector.getWorld().getBlockState(posUp);
if (stateUp.getBlock() == ModBlocks.ADVANCED_DETECTOR.getBlock()) {
if (ModBlocks.ADVANCED_DETECTOR.isAt(detector.getWorld(), posUp, stateUp)) {
((BlockRailAdvDetector) ModBlocks.ADVANCED_DETECTOR.getBlock()).refreshState(detector.getWorld(), posUp, stateUp, flag);
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"forge_marker": 1,
"defaults": {
"model": "rail_flat",
"textures": {"rail": "stevescarts:blocks/tracks/outfitted/kit/advanced_detector_0"}
},
"variants": {
"state": {
"0": {
"textures": {"rail": "stevescarts:blocks/tracks/outfitted/kit/advanced_detector_0"}
}
},
"shape": {
"north_south": {
"model": "rail_flat"
},
"east_west": {
"model": "rail_flat", "y": 90
}
}
}
}
Loading