Skip to content

Commit

Permalink
Inital 1.14 release
Browse files Browse the repository at this point in the history
  • Loading branch information
MrTroble committed Aug 5, 2021
1 parent 127ed7d commit f817071
Show file tree
Hide file tree
Showing 8 changed files with 84 additions and 74 deletions.
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ archivesBaseName = 'GIRC-Redstone'
sourceCompatibility = targetCompatibility = compileJava.sourceCompatibility = compileJava.targetCompatibility = '1.8'

minecraft {
mappings channel: 'snapshot', version: '20180921-1.13'
mappings channel: 'snapshot', version: '20190719-1.14.3'

runs {
client {
Expand All @@ -56,7 +56,7 @@ minecraft {
}

dependencies {
minecraft 'net.minecraftforge:forge:1.13.2-25.0.219'
minecraft 'net.minecraftforge:forge:1.14.4-28.2.0'
}

jar {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/eu/gir/gircredstone/block/BlockBasic.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
public class BlockBasic extends Block {

public BlockBasic(final String name) {
super(Properties.create(Material.CIRCUITS));
super(Properties.create(Material.MISCELLANEOUS));
this.setRegistryName(GIRCRedstoneMain.MODID, name);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package eu.gir.gircredstone.block;

import net.minecraft.block.Block;
import net.minecraft.block.state.IBlockState;
import net.minecraft.block.BlockState;
import net.minecraft.state.BooleanProperty;
import net.minecraft.state.StateContainer.Builder;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.Direction;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IBlockReader;

Expand All @@ -18,22 +18,22 @@ public BlockRedstoneAcceptor() {
}

@Override
public boolean canProvidePower(IBlockState state) {
public boolean canProvidePower(BlockState state) {
return true;
}

@Override
public int getWeakPower(IBlockState blockState, IBlockReader blockAccess, BlockPos pos, EnumFacing side) {
public int getWeakPower(BlockState blockState, IBlockReader blockAccess, BlockPos pos, Direction side) {
return this.getStrongPower(blockState, blockAccess, pos, side);
}

@Override
public int getStrongPower(IBlockState blockState, IBlockReader blockAccess, BlockPos pos, EnumFacing side) {
public int getStrongPower(BlockState blockState, IBlockReader blockAccess, BlockPos pos, Direction side) {
return blockState.get(POWER) ? 15:0;
}

@Override
protected void fillStateContainer(Builder<Block, IBlockState> builder) {
protected void fillStateContainer(Builder<Block, BlockState> builder) {
builder.add(POWER);
}

Expand Down
27 changes: 14 additions & 13 deletions src/main/java/eu/gir/gircredstone/block/BlockRedstoneEmitter.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
import eu.gir.gircredstone.init.GIRCInit;
import eu.gir.gircredstone.tile.TileRedstoneEmitter;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.block.ITileEntityProvider;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumHand;
import net.minecraft.util.Hand;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.text.TextComponentTranslation;
import net.minecraft.util.math.BlockRayTraceResult;
import net.minecraft.util.text.TranslationTextComponent;
import net.minecraft.world.IBlockReader;
import net.minecraft.world.World;

Expand All @@ -22,13 +22,13 @@ public BlockRedstoneEmitter() {
}

@Override
public TileEntity createTileEntity(IBlockState state, IBlockReader world) {
public TileEntity createTileEntity(BlockState state, IBlockReader world) {
return createNewTileEntity(world);
}

@Override
public boolean onBlockActivated(IBlockState state, World world, BlockPos pos, EntityPlayer player, EnumHand hand,
EnumFacing side, float hitX, float hitY, float hitZ) {
public boolean onBlockActivated(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand,
BlockRayTraceResult hit) {
if (world.isRemote)
return true;
if (player.getHeldItem(hand).getItem().equals(GIRCInit.RS_LINKER))
Expand All @@ -38,14 +38,14 @@ public boolean onBlockActivated(IBlockState state, World world, BlockPos pos, En
final TileRedstoneEmitter emitter = (TileRedstoneEmitter) entity;
final BlockPos linkedpos = emitter.getLinkedPos();
if (linkedpos == null) {
player.sendMessage(new TextComponentTranslation("em.notlinked"));
player.sendMessage(new TranslationTextComponent("em.notlinked"));
} else {
if (player.isSneaking()) {
emitter.unlink();
player.sendMessage(new TextComponentTranslation("em.unlink", linkedpos.getX(), linkedpos.getY(),
player.sendMessage(new TranslationTextComponent("em.unlink", linkedpos.getX(), linkedpos.getY(),
linkedpos.getZ()));
} else {
player.sendMessage(new TextComponentTranslation("lt.linkedpos", linkedpos.getX(), linkedpos.getY(),
player.sendMessage(new TranslationTextComponent("lt.linkedpos", linkedpos.getX(), linkedpos.getY(),
linkedpos.getZ()));
}
}
Expand All @@ -55,7 +55,8 @@ public boolean onBlockActivated(IBlockState state, World world, BlockPos pos, En
}

@Override
public void neighborChanged(IBlockState state, World world, BlockPos pos, Block blockIn, BlockPos fromPos) {
public void neighborChanged(BlockState state, World world, BlockPos pos, Block blockIn, BlockPos fromPos,
boolean isMoving) {
if (world.isRemote)
return;
final TileEntity entity = world.getTileEntity(pos);
Expand Down
7 changes: 3 additions & 4 deletions src/main/java/eu/gir/gircredstone/init/GIRCInit.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
import eu.gir.gircredstone.item.Linkingtool;
import eu.gir.gircredstone.tile.TileRedstoneEmitter;
import net.minecraft.block.Block;
import net.minecraft.item.BlockItem;
import net.minecraft.item.Item;
import net.minecraft.item.Item.Properties;
import net.minecraft.item.ItemBlock;
import net.minecraft.item.ItemGroup;
import net.minecraft.tileentity.TileEntityType;
import net.minecraftforge.event.RegistryEvent;
Expand All @@ -30,16 +30,15 @@ public static void registerBlock(RegistryEvent.Register<Block> event) {
IForgeRegistry<Block> registry = event.getRegistry();
registry.register(RS_ACCEPTOR);
registry.register(RS_EMITTER);
GIRCRedstoneMain.LOGGER.info("Hello!000000000000=========================================000000");
}

@SubscribeEvent
public static void registerItem(RegistryEvent.Register<Item> event) {
IForgeRegistry<Item> registry = event.getRegistry();
registry.register(new ItemBlock(RS_ACCEPTOR, new Properties().group(ItemGroup.REDSTONE))
registry.register(new BlockItem(RS_ACCEPTOR, new Properties().group(ItemGroup.REDSTONE))
.setRegistryName(RS_ACCEPTOR.getRegistryName()));
registry.register(RS_LINKER);
registry.register(new ItemBlock(RS_EMITTER, new Properties().group(ItemGroup.REDSTONE))
registry.register(new BlockItem(RS_EMITTER, new Properties().group(ItemGroup.REDSTONE))
.setRegistryName(RS_EMITTER.getRegistryName()));
}

Expand Down
67 changes: 33 additions & 34 deletions src/main/java/eu/gir/gircredstone/item/Linkingtool.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,16 @@
import eu.gir.gircredstone.tile.TileRedstoneEmitter;
import net.minecraft.block.Block;
import net.minecraft.client.util.ITooltipFlag;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.Item;
import net.minecraft.item.ItemGroup;
import net.minecraft.item.ItemStack;
import net.minecraft.item.ItemUseContext;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.EnumActionResult;
import net.minecraft.nbt.CompoundNBT;
import net.minecraft.util.ActionResultType;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.text.ITextComponent;
import net.minecraft.util.text.TextComponentTranslation;
import net.minecraft.util.text.TranslationTextComponent;
import net.minecraft.world.World;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
Expand All @@ -35,78 +35,77 @@ public Linkingtool() {
private static final String ID_Y = "yLinkedPos";
private static final String ID_Z = "zLinkedPos";

public static void writeBlockPosToNBT(BlockPos pos, NBTTagCompound compound) {
public static void writeBlockPosToNBT(BlockPos pos, CompoundNBT compound) {
if (pos != null && compound != null) {
compound.setInt(ID_X, pos.getX());
compound.setInt(ID_Y, pos.getY());
compound.setInt(ID_Z, pos.getZ());
compound.putInt(ID_X, pos.getX());
compound.putInt(ID_Y, pos.getY());
compound.putInt(ID_Z, pos.getZ());
}
}

public static BlockPos readBlockPosFromNBT(NBTTagCompound compound) {
if (compound != null && compound.hasKey(ID_X) && compound.hasKey(ID_Y) && compound.hasKey(ID_Z)) {
public static BlockPos readBlockPosFromNBT(CompoundNBT compound) {
if (compound != null && compound.contains(ID_X) && compound.contains(ID_Y) && compound.contains(ID_Z)) {
return new BlockPos(compound.getInt(ID_X), compound.getInt(ID_Y), compound.getInt(ID_Z));
}
return null;
}

@Override
public EnumActionResult onItemUse(ItemUseContext ctx) {
public ActionResultType onItemUseFirst(ItemStack stack, ItemUseContext ctx) {
final World worldIn = ctx.getWorld();
final EntityPlayer player = ctx.getPlayer();
final PlayerEntity player = ctx.getPlayer();
final BlockPos pos = ctx.getPos();
if (worldIn.isRemote)
return EnumActionResult.PASS;
return ActionResultType.PASS;
final Block block = worldIn.getBlockState(pos).getBlock();
final ItemStack stack = ctx.getItem();
if (player.isSneaking()) {
if (Linkingtool.readBlockPosFromNBT(stack.getTag()) != null) {
stack.setTag(null);
player.sendMessage(new TextComponentTranslation("lt.reset"));
return EnumActionResult.SUCCESS;
player.sendMessage(new TranslationTextComponent("lt.reset"));
return ActionResultType.SUCCESS;
}
}
if (block instanceof BlockRedstoneAcceptor) {
final NBTTagCompound comp = new NBTTagCompound();
final CompoundNBT comp = new CompoundNBT();
if (readBlockPosFromNBT(stack.getTag()) != null)
return EnumActionResult.FAIL;
return ActionResultType.FAIL;
writeBlockPosToNBT(pos, comp);
stack.setTag(comp);
player.sendMessage(new TextComponentTranslation("lt.setpos", pos.getX(), pos.getY(), pos.getZ()));
player.sendMessage(new TextComponentTranslation("lt.setpos.msg"));
return EnumActionResult.SUCCESS;
player.sendMessage(new TranslationTextComponent("lt.setpos", pos.getX(), pos.getY(), pos.getZ()));
player.sendMessage(new TranslationTextComponent("lt.setpos.msg"));
return ActionResultType.SUCCESS;
}
if (block instanceof BlockRedstoneEmitter) {
final TileRedstoneEmitter emitter = (TileRedstoneEmitter) worldIn.getTileEntity(pos);
final NBTTagCompound comp = stack.getTag();
final CompoundNBT comp = stack.getTag();
final BlockPos linkpos = Linkingtool.readBlockPosFromNBT(comp);
if (emitter.link(linkpos)) {
player.sendMessage(
new TextComponentTranslation("lt.linkedpos", linkpos.getX(), linkpos.getY(), linkpos.getZ()));
new TranslationTextComponent("lt.linkedpos", linkpos.getX(), linkpos.getY(), linkpos.getZ()));
stack.setTag(null);
player.sendMessage(new TextComponentTranslation("lt.reset"));
return EnumActionResult.SUCCESS;
player.sendMessage(new TranslationTextComponent("lt.reset"));
return ActionResultType.SUCCESS;
}
player.sendMessage(new TextComponentTranslation("lt.notlinked"));
player.sendMessage(new TextComponentTranslation("lt.notlinked.msg"));
return EnumActionResult.FAIL;
player.sendMessage(new TranslationTextComponent("lt.notlinked"));
player.sendMessage(new TranslationTextComponent("lt.notlinked.msg"));
return ActionResultType.FAIL;
}
return EnumActionResult.FAIL;
return ActionResultType.FAIL;
}

@OnlyIn(Dist.CLIENT)
@Override
public void addInformation(ItemStack stack, @Nullable World worldIn, List<ITextComponent> tooltip, ITooltipFlag flagIn) {
final NBTTagCompound nbt = stack.getTag();
final CompoundNBT nbt = stack.getTag();
if (nbt != null) {
final BlockPos pos = Linkingtool.readBlockPosFromNBT(nbt);
if (pos != null) {
tooltip.add(new TextComponentTranslation("lt.linkedpos", pos.getX(), pos.getY(), pos.getZ()));
tooltip.add(new TranslationTextComponent("lt.linkedpos", pos.getX(), pos.getY(), pos.getZ()));
return;
}
}
tooltip.add(new TextComponentTranslation("lt.notlinked"));
tooltip.add(new TextComponentTranslation("lt.notlinked.msg"));
tooltip.add(new TranslationTextComponent("lt.notlinked"));
tooltip.add(new TranslationTextComponent("lt.notlinked.msg"));
}

}
37 changes: 24 additions & 13 deletions src/main/java/eu/gir/gircredstone/tile/TileRedstoneEmitter.java
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
package eu.gir.gircredstone.tile;

import com.google.common.collect.Lists;
import java.util.concurrent.ExecutionException;

import eu.gir.gircredstone.block.BlockRedstoneAcceptor;
import eu.gir.gircredstone.init.GIRCInit;
import eu.gir.gircredstone.item.Linkingtool;
import net.minecraft.block.state.IBlockState;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.block.BlockState;
import net.minecraft.nbt.CompoundNBT;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.chunk.Chunk;
import net.minecraft.world.gen.ChunkProviderServer;
import net.minecraft.world.server.ServerChunkProvider;

public class TileRedstoneEmitter extends TileEntity {

Expand All @@ -21,13 +21,13 @@ public TileRedstoneEmitter() {
private BlockPos linkedpos = null;

@Override
public NBTTagCompound write(NBTTagCompound compound) {
public CompoundNBT write(CompoundNBT compound) {
Linkingtool.writeBlockPosToNBT(linkedpos, compound);
return super.write(compound);
}

@Override
public void read(NBTTagCompound compound) {
public void read(CompoundNBT compound) {
super.read(compound);
this.linkedpos = Linkingtool.readBlockPosFromNBT(compound);
}
Expand All @@ -51,22 +51,33 @@ public BlockPos getLinkedPos() {
}

public void accept(final boolean enabled) {
final IBlockState state = world.getBlockState(linkedpos);
final BlockState state = world.getBlockState(linkedpos);
if (state.getBlock() instanceof BlockRedstoneAcceptor) {
world.setBlockState(linkedpos, state.with(BlockRedstoneAcceptor.POWER, enabled));
}
}

@SuppressWarnings("deprecation")
public void redstoneUpdate(final boolean enabled) {
if (linkedpos != null) {
final boolean flag = !world.isBlockLoaded(linkedpos);
if(flag) {
final Chunk chunk = world.getChunk(linkedpos);
final ChunkProviderServer provider = (ChunkProviderServer) world.getChunkProvider();
provider.loadChunks(Lists.newArrayList(chunk.getPos()), ch -> {
accept(enabled);
provider.queueUnload(ch);
});
final Chunk chunk = world.getChunkAt(linkedpos);
final ServerChunkProvider provider = (ServerChunkProvider) world.getChunkProvider();
try {
provider.chunkManager.func_219188_b(chunk.getPos()).get().ifLeft(ch -> {
accept(enabled);
try {
provider.chunkManager.func_222973_a(chunk).get();
} catch (InterruptedException | ExecutionException e) {
e.printStackTrace();
}
});
} catch (InterruptedException e) {
e.printStackTrace();
} catch (ExecutionException e) {
e.printStackTrace();
}
return;
}
accept(enabled);
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/META-INF/mods.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@ Works in unloaded Chunks TM.
[[dependencies.gircredstone]]
modId="minecraft"
mandatory=true
versionRange="[1.13.2]"
versionRange="[1.14.4]"
ordering="NONE"
side="BOTH"

0 comments on commit f817071

Please sign in to comment.