parent
79582cd94b
commit
73b2f36b24
4 changed files with 101 additions and 15 deletions
|
@ -24,12 +24,23 @@
|
|||
|
||||
package techreborn.blocks;
|
||||
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.EnumHand;
|
||||
import net.minecraft.util.SoundCategory;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
import prospector.shootingstar.ShootingStar;
|
||||
import prospector.shootingstar.model.ModelCompound;
|
||||
import reborncore.api.ToolManager;
|
||||
import reborncore.api.tile.IMachineGuiHandler;
|
||||
import reborncore.common.blocks.BlockMachineBase;
|
||||
import techreborn.client.EGui;
|
||||
import techreborn.client.TechRebornCreativeTab;
|
||||
import techreborn.init.ModBlocks;
|
||||
import techreborn.init.ModSounds;
|
||||
import techreborn.lib.ModInfo;
|
||||
|
||||
public class BlockComputerCube extends BlockMachineBase {
|
||||
|
@ -43,6 +54,32 @@ public class BlockComputerCube extends BlockMachineBase {
|
|||
|
||||
@Override
|
||||
public IMachineGuiHandler getGui() {
|
||||
return EGui.MANUAL;
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn,
|
||||
EnumHand hand, EnumFacing side, float hitX, float hitY, float hitZ) {
|
||||
|
||||
ItemStack tool = playerIn.getHeldItem(EnumHand.MAIN_HAND);
|
||||
if (!tool.isEmpty() && ToolManager.INSTANCE.canHandleTool(tool)) {
|
||||
if (ToolManager.INSTANCE.handleTool(tool, pos, worldIn, playerIn, side, false)) {
|
||||
if (playerIn.isSneaking()) {
|
||||
ItemStack drop = new ItemStack(ModBlocks.COMPUTER_CUBE, 1);
|
||||
spawnAsEntity(worldIn, pos, drop);
|
||||
worldIn.playSound(null, playerIn.posX, playerIn.posY, playerIn.posZ, ModSounds.BLOCK_DISMANTLE,
|
||||
SoundCategory.BLOCKS, 0.6F, 1F);
|
||||
if (!worldIn.isRemote) {
|
||||
worldIn.setBlockState(pos, Blocks.AIR.getDefaultState(), 2);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
rotateBlock(worldIn, pos, side);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -30,6 +30,7 @@ import net.minecraft.block.state.IBlockState;
|
|||
import net.minecraft.creativetab.CreativeTabs;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
|
@ -47,6 +48,8 @@ import net.minecraftforge.fml.relauncher.Side;
|
|||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
import prospector.shootingstar.ShootingStar;
|
||||
import prospector.shootingstar.model.ModelCompound;
|
||||
import reborncore.api.IToolDrop;
|
||||
import reborncore.api.ToolManager;
|
||||
import reborncore.api.tile.IMachineGuiHandler;
|
||||
import reborncore.common.blocks.BlockMachineBase;
|
||||
import reborncore.common.blocks.PropertyString;
|
||||
|
@ -140,22 +143,51 @@ public class BlockPlayerDetector extends BlockMachineBase {
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer entityPlayer,
|
||||
public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn,
|
||||
EnumHand hand, EnumFacing side, float hitX, float hitY, float hitZ) {
|
||||
ItemStack stack = playerIn.getHeldItem(EnumHand.MAIN_HAND);
|
||||
TileEntity tileEntity = worldIn.getTileEntity(pos);
|
||||
|
||||
if (tileEntity == null) {
|
||||
return super.onBlockActivated(worldIn, pos, state, playerIn, hand, side, hitX, hitY, hitZ);
|
||||
}
|
||||
|
||||
String type = state.getValue(TYPE);
|
||||
String newType = type;
|
||||
TextFormatting color = TextFormatting.GREEN;
|
||||
if (type.equals("all")) {
|
||||
newType = "others";
|
||||
color = TextFormatting.RED;
|
||||
} else if (type.equals("others")) {
|
||||
newType = "you";
|
||||
color = TextFormatting.BLUE;
|
||||
} else if (type.equals("you")) {
|
||||
newType = "all";
|
||||
|
||||
if (!stack.isEmpty() && ToolManager.INSTANCE.canHandleTool(stack)) {
|
||||
if (ToolManager.INSTANCE.handleTool(stack, pos, worldIn, playerIn, side, false)) {
|
||||
if (playerIn.isSneaking()) {
|
||||
if (tileEntity instanceof IToolDrop) {
|
||||
ItemStack drop = ((IToolDrop) tileEntity).getToolDrop(playerIn);
|
||||
if (drop == null) {
|
||||
return false;
|
||||
}
|
||||
if (!drop.isEmpty()) {
|
||||
spawnAsEntity(worldIn, pos, drop);
|
||||
}
|
||||
if (!worldIn.isRemote) {
|
||||
worldIn.setBlockState(pos, Blocks.AIR.getDefaultState(), 2);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
} else {
|
||||
if (type.equals("all")) {
|
||||
newType = "others";
|
||||
color = TextFormatting.RED;
|
||||
} else if (type.equals("others")) {
|
||||
newType = "you";
|
||||
color = TextFormatting.BLUE;
|
||||
} else if (type.equals("you")) {
|
||||
newType = "all";
|
||||
}
|
||||
worldIn.setBlockState(pos, state.withProperty(TYPE, newType));
|
||||
}
|
||||
}
|
||||
}
|
||||
world.setBlockState(pos, state.withProperty(TYPE, newType));
|
||||
if (world.isRemote) {
|
||||
|
||||
if (worldIn.isRemote) {
|
||||
ChatUtils.sendNoSpamMessages(MessageIDs.playerDetectorID, new TextComponentString(
|
||||
TextFormatting.GRAY + I18n.format("techreborn.message.detects") + " " + color
|
||||
+ StringUtils.toFirstCapital(newType)));
|
||||
|
|
|
@ -38,6 +38,8 @@ import net.minecraft.util.ResourceLocation;
|
|||
import net.minecraft.util.SoundCategory;
|
||||
import net.minecraftforge.fml.common.registry.ForgeRegistries;
|
||||
import org.apache.commons.lang3.tuple.Pair;
|
||||
|
||||
import reborncore.api.IToolDrop;
|
||||
import reborncore.api.tile.IInventoryProvider;
|
||||
import reborncore.common.powerSystem.TilePowerAcceptor;
|
||||
import reborncore.common.util.Inventory;
|
||||
|
@ -45,6 +47,7 @@ import reborncore.common.util.ItemUtils;
|
|||
import techreborn.client.container.IContainerProvider;
|
||||
import techreborn.client.container.builder.BuiltContainer;
|
||||
import techreborn.client.container.builder.ContainerBuilder;
|
||||
import techreborn.init.ModBlocks;
|
||||
import techreborn.init.ModSounds;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
@ -54,7 +57,8 @@ import java.util.List;
|
|||
/**
|
||||
* Created by modmuss50 on 20/06/2017.
|
||||
*/
|
||||
public class TileAutoCraftingTable extends TilePowerAcceptor implements IContainerProvider, IInventoryProvider {
|
||||
public class TileAutoCraftingTable extends TilePowerAcceptor
|
||||
implements IContainerProvider, IInventoryProvider, IToolDrop {
|
||||
|
||||
ResourceLocation currentRecipe;
|
||||
|
||||
|
@ -445,4 +449,9 @@ public class TileAutoCraftingTable extends TilePowerAcceptor implements IContain
|
|||
public EnumFacing getFacingEnum() {
|
||||
return EnumFacing.NORTH;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getToolDrop(EntityPlayer playerIn) {
|
||||
return new ItemStack(ModBlocks.AUTO_CRAFTING_TABLE, 1);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -25,19 +25,22 @@
|
|||
package techreborn.tiles;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import reborncore.api.IToolDrop;
|
||||
import reborncore.common.blocks.BlockMachineBase;
|
||||
import reborncore.common.powerSystem.TilePowerAcceptor;
|
||||
import reborncore.common.registration.RebornRegistry;
|
||||
import reborncore.common.registration.impl.ConfigRegistry;
|
||||
import reborncore.common.util.WorldUtils;
|
||||
import techreborn.init.ModBlocks;
|
||||
import techreborn.lib.ModInfo;
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
@RebornRegistry(modID = ModInfo.MOD_ID)
|
||||
public class TilePlayerDectector extends TilePowerAcceptor {
|
||||
public class TilePlayerDectector extends TilePowerAcceptor implements IToolDrop {
|
||||
|
||||
@ConfigRegistry(config = "machines", category = "player_detector", key = "PlayerDetectorMaxInput", comment = "Player Detector Max Input (Value in EU)")
|
||||
public static int maxInput = 32;
|
||||
|
@ -128,4 +131,9 @@ public class TilePlayerDectector extends TilePowerAcceptor {
|
|||
tag.setString("ownerID", owenerUdid);
|
||||
return tag;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getToolDrop(EntityPlayer p0) {
|
||||
return new ItemStack(ModBlocks.PLAYER_DETECTOR, 1, 0);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue