Commit 7155745f authored by primetoxinz's avatar primetoxinz

Partial MCMultipart2 support for Mini blocks, currently disabled. Slight improvements to HCSpawn.

parent dbb52eb0
......@@ -24,3 +24,5 @@ classes
# other
eclipse
run*
/src/main/java/mcmultipart/test/
/src/main/resources/assets/mcmultiparttest/
......@@ -34,12 +34,14 @@ repositories {
name "Base"
url "http://blamejared.com/maven"
}
maven { url "http://maven.amadornes.com/" }
}
dependencies {
deobfCompile "mezz.jei:jei_1.11.2:+"
deobfCompile "MineTweaker3:MineTweaker3-API:+"
deobfCompile "com.blamejared:MTLib:2.+"
runtime "MineTweaker3:MineTweaker3-MC1112-Main:+"
deobfCompile "MCMultiPart2:MCMultiPart-exp:+"
}
......
......@@ -17,7 +17,7 @@ import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
* Created by blueyu2 on 11/28/16.
*/
public class HardcoreRedstoneEvent {
//TODO This caused some pretty severe crashes when testing mcmultipart, keep an eye on it.
@SubscribeEvent
public void disableRedstone(BlockEvent.NeighborNotifyEvent event) {
if (!BWConfig.hardcoreRedstone)
......@@ -33,11 +33,13 @@ public class HardcoreRedstoneEvent {
if (!state.getMaterial().equals(Material.IRON))
continue;
}
world.neighborChanged(pos.offset(facing), event.getState().getBlock(), pos);
for (EnumFacing f1 : EnumFacing.VALUES) {
if (f1 != facing.getOpposite())
world.neighborChanged(pos.offset(facing).offset(f1), event.getState().getBlock(), pos.offset(facing));
}
}
if (event.getForceRedstoneUpdate()) {
event.getWorld().updateObservingBlocksAt(pos, event.getState().getBlock());
}
}
}
......@@ -9,7 +9,9 @@ import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.stats.StatList;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.MathHelper;
import net.minecraft.util.text.TextComponentTranslation;
import net.minecraft.world.World;
import net.minecraftforge.common.util.EnumHelper;
import net.minecraftforge.event.entity.living.LivingDeathEvent;
import net.minecraftforge.event.entity.player.PlayerSleepInBedEvent;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
......@@ -21,8 +23,11 @@ import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
*/
public class RespawnEventHandler {
static final int HARDCORE_SPAWN_RADIUS = 2000;
static final int HARDCORE_SPAWN_COOLDOWN = 24000;//20 min
static final int HARDCORE_SPAWN_COOLDOWN_RADIUS = 100;
static final int HARDCORE_SPAWN_COOLDOWN = 0;//24000;//20 min
static final int HARDCORE_SPAWN_MAX_ATTEMPTS = 20;
static final EntityPlayer.SleepResult TOO_RESTLESS = EnumHelper.addEnum(EntityPlayer.SleepResult.class, "TOO_RESTLESS", new Class[0], new Object[0]);
/**
* Disable Beds
......@@ -30,7 +35,10 @@ public class RespawnEventHandler {
@SubscribeEvent
public void onSleepInBed(PlayerSleepInBedEvent event) {
if (!BWConfig.hardcoreBeds) return;
if (EntityPlayerExt.isSurvival(event.getEntityPlayer())) event.setResult(EntityPlayer.SleepResult.NOT_SAFE);
if (EntityPlayerExt.isSurvival(event.getEntityPlayer())) {
event.getEntityPlayer().sendStatusMessage(new TextComponentTranslation("tile.bed.tooRestless", new Object[0]), true);
event.setResult(TOO_RESTLESS);
}
}
/**
......@@ -43,7 +51,7 @@ public class RespawnEventHandler {
EntityPlayerMP player = (EntityPlayerMP) event.getEntity();
if (EntityPlayerExt.isSurvival(player)) {
int timeSinceDeath = player.getStatFile().readStat(StatList.TIME_SINCE_DEATH);
int spawnFuzz = timeSinceDeath >= HARDCORE_SPAWN_COOLDOWN ? HARDCORE_SPAWN_RADIUS : 100;
int spawnFuzz = timeSinceDeath >= HARDCORE_SPAWN_COOLDOWN ? HARDCORE_SPAWN_RADIUS : HARDCORE_SPAWN_COOLDOWN_RADIUS;
BlockPos newPos = getRespawnPoint(player, spawnFuzz);
player.setSpawnPoint(newPos, true);
}
......
package betterwithmods.integration.mcmultipart;
import betterwithmods.BWMod;
import betterwithmods.common.BWMBlocks;
import betterwithmods.common.blocks.BlockAxle;
import betterwithmods.common.blocks.mini.BlockCorner;
import betterwithmods.common.blocks.mini.BlockMoulding;
import betterwithmods.common.blocks.mini.BlockSiding;
import betterwithmods.util.DirUtils;
import mcmultipart.api.addon.IMCMPAddon;
import mcmultipart.api.addon.IWrappedBlock;
import mcmultipart.api.multipart.IMultipartRegistry;
import mcmultipart.api.multipart.MultipartHelper;
import mcmultipart.api.ref.MCMPCapabilities;
import mcmultipart.api.slot.EnumCenterSlot;
import mcmultipart.api.slot.EnumCornerSlot;
import mcmultipart.api.slot.EnumEdgeSlot;
import mcmultipart.api.slot.EnumFaceSlot;
import mcmultipart.api.slot.IPartSlot;
import net.minecraft.block.Block;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.item.Item;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumHand;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.common.capabilities.Capability;
import net.minecraftforge.common.capabilities.ICapabilityProvider;
import net.minecraftforge.event.AttachCapabilitiesEvent;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.Optional;
import java.util.function.Function;
/**
* Purpose:
*
* @author Tyler Marshall
* @version 2/26/17
*/
//@MCMPAddon
public class MCMultipart implements IMCMPAddon {
@Override
public void registerParts(IMultipartRegistry registry) {
MinecraftForge.EVENT_BUS.register(this);
registerProxy(registry, BWMBlocks.WOOD_SIDING, this::siding).setPlacementInfo(this::getSidingState);
registerProxy(registry, BWMBlocks.STONE_SIDING, this::siding).setPlacementInfo(this::getSidingState);
registerProxy(registry, BWMBlocks.WOOD_MOULDING, this::moulding).setPlacementInfo(this::getMouldingState);
registerProxy(registry, BWMBlocks.STONE_MOULDING, this::moulding).setPlacementInfo(this::getMouldingState);
registerProxy(registry, BWMBlocks.WOOD_CORNER, this::corner).setPlacementInfo(this::getCornerState);
registerProxy(registry, BWMBlocks.STONE_CORNER, this::corner).setPlacementInfo(this::getCornerState);
registerProxy(registry, BWMBlocks.DIRT_SLAB, s -> EnumFaceSlot.DOWN);
// registry.registerPartWrapper(BWMBlocks.AXLE, new PartAxle());
// registry.registerStackWrapper(Item.getItemFromBlock(BWMBlocks.AXLE), i -> true, BWMBlocks.AXLE);
}
private IBlockState getCornerState(World world, BlockPos pos, EnumFacing facing, float hitX, float hitY, float hitZ, int meta,
EntityLivingBase placer, EnumHand hand, IBlockState state) {
return state;
}
private IBlockState getMouldingState(World world, BlockPos pos, EnumFacing facing, float hitX, float hitY, float hitZ, int meta,
EntityLivingBase placer, EnumHand hand, IBlockState state) {
double p = Math.abs(hitX * facing.getFrontOffsetX() + hitY * facing.getFrontOffsetY() + hitZ * facing.getFrontOffsetZ());
if (p == 0.5) {
int ori = DirUtils.getPlacementMeta("moulding", facing.getOpposite(), hitX, hitY, hitZ);
return state.withProperty(BlockMoulding.ORIENTATION, ori);
}
return state;
}
private IBlockState getSidingState(World world, BlockPos pos, EnumFacing facing, float hitX, float hitY, float hitZ, int meta,
EntityLivingBase placer, EnumHand hand, IBlockState state) {
boolean occupied = false;
switch (facing.getAxis()) {
case X:
occupied = hitX == 0.5;
break;
case Y:
occupied = hitY == 0.5;
break;
case Z:
occupied = hitZ == 0.5;
break;
}
if (occupied)
return state.withProperty(BlockSiding.ORIENTATION, facing.ordinal());
return state;
}
public IPartSlot corner(IBlockState state) {
int o = state.getValue(BlockCorner.ORIENTATION);
EnumCornerSlot[] order = new EnumCornerSlot[]{EnumCornerSlot.CORNER_NNP, EnumCornerSlot.CORNER_NNN, EnumCornerSlot.CORNER_PNP, EnumCornerSlot.CORNER_PNN, EnumCornerSlot.CORNER_NPP, EnumCornerSlot.CORNER_NPN, EnumCornerSlot.CORNER_PPP, EnumCornerSlot.CORNER_PPN, EnumCornerSlot.CORNER_NNN,};
return order[o];
}
public IPartSlot siding(IBlockState state) {
return EnumFaceSlot.VALUES[state.getValue(BlockSiding.ORIENTATION)];
}
public IPartSlot moulding(IBlockState state) {
int o = state.getValue(BlockMoulding.ORIENTATION);
EnumFacing[] facing = new EnumFacing[]{EnumFacing.WEST, EnumFacing.NORTH, EnumFacing.SOUTH, EnumFacing.EAST};
EnumFacing one = o < 4 ? EnumFacing.DOWN : o < 8 ? EnumFacing.UP : o < 10 ? EnumFacing.NORTH : EnumFacing.SOUTH;
EnumFacing two = o < 8 ? facing[o % 4] : facing[o % 2];
Optional<EnumEdgeSlot> slot = Optional.ofNullable(EnumEdgeSlot.fromFaces(one, two));
return slot.orElse(EnumEdgeSlot.EDGE_XNN);
}
public IWrappedBlock registerProxy(IMultipartRegistry registry, Block block, Function<IBlockState, IPartSlot> placement, Function<IBlockState, IPartSlot> world) {
registry.registerPartWrapper(block, new MultipartProxy(block, placement, world));
return registry.registerStackWrapper(Item.getItemFromBlock(block), s -> true, block);
}
public IWrappedBlock registerProxy(IMultipartRegistry registry, Block block, Function<IBlockState, IPartSlot> wrapper) {
return registerProxy(registry, block, wrapper, wrapper);
}
public static int getPowerLevel(World world, BlockPos pos, EnumFacing side) {
if (MultipartHelper.getPart(world, pos, EnumCenterSlot.CENTER).orElse(null) instanceof PartAxle) {
IBlockState state = MultipartHelper.getPartState(world, pos, EnumCenterSlot.CENTER).orElse(null);
if (state != null && state.getValue(BlockAxle.AXIS).apply(side)) {
return state.getValue(BlockAxle.SIGNAL);
}
}
return 0;
}
@SubscribeEvent
public void onAttachCapability(AttachCapabilitiesEvent<TileEntity> e) {
register(e, "miniblock");
}
private void register(AttachCapabilitiesEvent<TileEntity> e, String id) {
e.addCapability(new ResourceLocation(BWMod.MODID, id), new ICapabilityProvider() {
private PartTile tile;
@Override
public boolean hasCapability(@Nonnull Capability<?> capability, @Nullable EnumFacing facing) {
return capability == MCMPCapabilities.MULTIPART_TILE;
}
@Nullable
@Override
public <T> T getCapability(@Nonnull Capability<T> capability, @Nullable EnumFacing facing) {
if (capability == MCMPCapabilities.MULTIPART_TILE) {
if (tile == null) {
tile = new PartTile(e.getObject());
}
return MCMPCapabilities.MULTIPART_TILE.cast(tile);
}
return null;
}
});
}
}
package betterwithmods.integration.mcmultipart;
import mcmultipart.api.multipart.IMultipart;
import mcmultipart.api.slot.IPartSlot;
import net.minecraft.block.Block;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import java.util.function.Function;
/**
* Purpose:
*
* @author Tyler Marshall
* @version 2/27/17
*/
public class MultipartProxy implements IMultipart {
private final Block block;
private final Function<IBlockState, IPartSlot> placementWrapper, worldWrapper;
public MultipartProxy(Block block, Function<IBlockState, IPartSlot> placementWrapper, Function<IBlockState, IPartSlot> worldWrapper) {
this.block = block;
this.placementWrapper = placementWrapper;
this.worldWrapper = worldWrapper;
}
public MultipartProxy(Block block, Function<IBlockState, IPartSlot> wrapper) {
this(block,wrapper,wrapper);
}
@Override
public Block getBlock() {
return block;
}
@Override
public IPartSlot getSlotForPlacement(World world, BlockPos pos, IBlockState state, EnumFacing facing, float hitX, float hitY, float hitZ, EntityLivingBase placer) {
return placementWrapper.apply(state);
}
@Override
public IPartSlot getSlotFromWorld(IBlockAccess world, BlockPos pos, IBlockState state) {
return worldWrapper.apply(state);
}
}
package betterwithmods.integration.mcmultipart;
import betterwithmods.common.BWMBlocks;
import mcmultipart.api.container.IPartInfo;
import mcmultipart.api.multipart.IMultipart;
import mcmultipart.api.slot.EnumCenterSlot;
import mcmultipart.api.slot.IPartSlot;
import net.minecraft.block.Block;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumHand;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.RayTraceResult;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import java.util.Random;
/**
* Purpose:
*
* @author Tyler Marshall
* @version 2/26/17
*/
public class PartAxle implements IMultipart {
@Override
public boolean onPartActivated(IPartInfo part, EntityPlayer player, EnumHand hand, RayTraceResult hit) {
return false;
}
@Override
public void updateTick(IPartInfo part, Random rand) {
part.getState().getBlock().updateTick(part.getWorld(), part.getPos(), part.getState(), rand);
}
@Override
public Block getBlock() {
return BWMBlocks.AXLE;
}
@Override
public IPartSlot getSlotForPlacement(World world, BlockPos pos, IBlockState state, EnumFacing facing, float hitX, float hitY, float hitZ, EntityLivingBase placer) {
return EnumCenterSlot.CENTER;
}
@Override
public IPartSlot getSlotFromWorld(IBlockAccess world, BlockPos pos, IBlockState state) {
return EnumCenterSlot.CENTER;
}
}
package betterwithmods.integration.mcmultipart;
import mcmultipart.api.container.IPartInfo;
import mcmultipart.api.multipart.IMultipartTile;
import net.minecraft.tileentity.TileEntity;
/**
* Purpose:
*
* @author Tyler Marshall
* @version 2/27/17
*/
public class PartTile implements IMultipartTile {
private TileEntity tile;
private IPartInfo info;
public PartTile(TileEntity tile) {
this.tile = tile;
}
@Override
public void setPartInfo(IPartInfo info) {
this.info = info;
}
@Override
public TileEntity getTileEntity() {
return tile;
}
public IPartInfo getInfo() {
return info;
}
}
......@@ -384,4 +384,6 @@ bwm.config.pulley.tooltip=Limitations of the platforms of the pulley
bwm.effect.true_sight=True Sight
config.sync.restart=Server changes to the configs require a client restart. Sorry about that.
config.sync.ok=Changes to the configs successful. If you see issues from not restarting the client, please report it to the server admins so they can report the changes made to the config file.
\ No newline at end of file
config.sync.ok=Changes to the configs successful. If you see issues from not restarting the client, please report it to the server admins so they can report the changes made to the config file.
tile.bed.tooRestless=You are too restless to sleep
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment