Jump to content

arkeN

Members
  • Posts

    11
  • Joined

  • Last visited

Recent Profile Visitors

The recent visitors block is disabled and is not being shown to other users.

arkeN's Achievements

Tree Puncher

Tree Puncher (2/8)

0

Reputation

  1. Dear Modding Community, I'm working on an Wireless Redstone Modification, I am using WorldSaveData to save the Receiver and Transmitter Blocks, but the Power Output of my Receiver Block doesn't change. What is wrong? Thanks in advance Aaron RedstoneReceiverList: public class RedstoneReceiverList extends WorldSavedData { private static RedstoneReceiverList clientInstance = new RedstoneReceiverList(); public final HashMap<BlockPos, String> receiver = new HashMap<>(); public static final String RECEIVER_ID = BetterRedstone.MOD_ID + "_RECEIVER"; public static RedstoneReceiverList get(World w) { if(!w.isRemote) { DimensionSavedDataManager storage = ((ServerWorld) w).getSavedData(); return storage.getOrCreate(RedstoneReceiverList::new, RECEIVER_ID); }else { return clientInstance; } } public RedstoneReceiverList() { super(RECEIVER_ID); } public RedstoneReceiverList(String id) { super(id); } @Override public void read(@Nonnull CompoundNBT nbt) { this.receiver.clear(); if(nbt.contains("receiver", Constants.NBT.TAG_LIST)) { ListNBT list = nbt.getList("receiver", Constants.NBT.TAG_COMPOUND); for(int i = 0; i < list.size(); i++) { CompoundNBT entryNBT = list.getCompound(i); if(entryNBT.contains("x") && entryNBT.contains("y") && entryNBT.contains("z") && entryNBT.contains("id")) { BlockPos pos = new BlockPos(entryNBT.getInt("x"), entryNBT.getInt("y"), entryNBT.getInt("z")).toImmutable(); String id = entryNBT.getString("id"); if(!id.isEmpty()) { this.receiver.put(pos, entryNBT.getString("id")); } } } } } @Override public CompoundNBT write(CompoundNBT nbt) { ListNBT list = new ListNBT(); for(Map.Entry<BlockPos, String> entry : this.receiver.entrySet()) { CompoundNBT entryNBT = new CompoundNBT(); entryNBT.putInt("x", entry.getKey().getX()); entryNBT.putInt("y", entry.getKey().getY()); entryNBT.putInt("z", entry.getKey().getZ()); entryNBT.putString("id", entry.getValue()); list.add(entryNBT); } nbt.put("receiver", list); return nbt; } public void setReceiver(World w, BlockPos pos, @Nullable String id) { if(!w.isRemote) { BlockPos immutablePos = pos.toImmutable(); if(id == null || id.trim().isEmpty()) { if(this.receiver.containsKey(immutablePos)) { this.receiver.remove(immutablePos); } }else{ String oldID = this.receiver.getOrDefault(immutablePos, null); if(oldID == null || !oldID.equals(id)) { this.receiver.put(pos.toImmutable(), id); } } this.markDirty(); } } public String getReceiver(BlockPos pos) { return this.receiver.getOrDefault(pos.toImmutable(), null); } } RedstoneTransmitterList: public class RedstoneTransmitterList extends WorldSavedData { private static RedstoneTransmitterList clientInstance = new RedstoneTransmitterList(); public final HashMap<BlockPos, String> transmitter = new HashMap<>(); public static final String TRANSMITTER_ID = BetterRedstone.MOD_ID + "_TRANSMITTER"; public static RedstoneTransmitterList get(World w) { if(!w.isRemote) { DimensionSavedDataManager storage = ((ServerWorld) w).getSavedData(); return storage.getOrCreate(RedstoneTransmitterList::new, TRANSMITTER_ID); }else { return clientInstance; } } public RedstoneTransmitterList() { super(TRANSMITTER_ID); } public RedstoneTransmitterList(String id) { super(id); } @Override public void read(@Nonnull CompoundNBT nbt) { this.transmitter.clear(); if(nbt.contains("transmitter", Constants.NBT.TAG_LIST)) { ListNBT list = nbt.getList("transmitter", Constants.NBT.TAG_COMPOUND); for(int i = 0; i < list.size(); i++) { CompoundNBT entryNBT = list.getCompound(i); if(entryNBT.contains("x") && entryNBT.contains("y") && entryNBT.contains("z") && entryNBT.contains("id")) { BlockPos pos = new BlockPos(entryNBT.getInt("x"), entryNBT.getInt("y"), entryNBT.getInt("z")).toImmutable(); String id = entryNBT.getString("id"); if(!id.isEmpty()) { this.transmitter.put(pos, entryNBT.getString("id")); } } } } } @Override public CompoundNBT write(CompoundNBT nbt) { ListNBT list = new ListNBT(); for(Map.Entry<BlockPos, String> entry : this.transmitter.entrySet()) { CompoundNBT entryNBT = new CompoundNBT(); entryNBT.putInt("x", entry.getKey().getX()); entryNBT.putInt("y", entry.getKey().getY()); entryNBT.putInt("z", entry.getKey().getZ()); entryNBT.putString("id", entry.getValue()); list.add(entryNBT); } nbt.put("transmitter", list); return nbt; } public void setTransmitter(World w, BlockPos pos, @Nullable String id) { if(!w.isRemote) { BlockPos immutablePos = pos.toImmutable(); if(id == null || id.trim().isEmpty()) { if(this.transmitter.containsKey(immutablePos)) { this.transmitter.remove(immutablePos); } }else{ String oldID = this.transmitter.getOrDefault(immutablePos, null); if(oldID == null || !oldID.equals(id)) { this.transmitter.put(pos.toImmutable(), id); } } this.markDirty(); } } public String getTransmitter(BlockPos pos) { return this.transmitter.getOrDefault(pos.toImmutable(), null); } } RedstoneReceiverBlock: public class RedstoneReceiverBlock extends Block { public static final IntegerProperty ID = IntegerProperty.create("id", 0, 99); int power = 0; public RedstoneReceiverBlock() { super(AbstractBlock.Properties.create(Material.IRON, MaterialColor.EMERALD)); this.setDefaultState(this.getStateContainer().getBaseState().with(ID, 0)); } @Override public boolean canProvidePower(BlockState state) { return true; } @Override public boolean canConnectRedstone(BlockState state, IBlockReader world, BlockPos pos, Direction side) { return true; } @Override public int getWeakPower(BlockState blockState, IBlockReader blockAccess, BlockPos pos, Direction side) { return power; } @Override protected void fillStateContainer(StateContainer.Builder<Block, BlockState> builder) { builder.add(ID); } @Override public void onBlockPlacedBy(World worldIn, BlockPos pos, BlockState state, @Nullable LivingEntity placer, ItemStack stack) { super.onBlockPlacedBy(worldIn, pos, state, placer, stack); RedstoneReceiverList.get(worldIn).setReceiver(worldIn, pos, state.getValues().get(ID).toString()); BlockPos blockPos = getSingleKeyFromValue(RedstoneTransmitterList.get(worldIn).transmitter, state.getValues().get(ID).toString()); if(RedstoneUtil.isPowered(worldIn, blockPos)) { power = 15; }else{ power = 0; } } @Override public void onReplaced(BlockState state, World worldIn, BlockPos pos, BlockState newState, boolean isMoving) { super.onReplaced(state, worldIn, pos, newState, isMoving); RedstoneReceiverList.get(worldIn).setReceiver(worldIn, pos, null); } public static <K, V> K getSingleKeyFromValue(Map<K, V> map, V value) { for (Map.Entry<K, V> entry : map.entrySet()) { if (Objects.equals(value, entry.getValue())) { return entry.getKey(); } } return null; } } RedstoneTransmitterBlock: public class RedstoneTransmitterBlock extends LeverBlock { public static final IntegerProperty ID = IntegerProperty.create("id", 0, 99); public RedstoneTransmitterBlock() { super(AbstractBlock.Properties.create(Material.IRON, MaterialColor.EMERALD)); this.setDefaultState(this.getStateContainer().getBaseState().with(ID, 0)); } @Override protected void fillStateContainer(StateContainer.Builder<Block, BlockState> builder) { builder.add(ID, FACE, HORIZONTAL_FACING, POWERED); } @Override public void onBlockPlacedBy(World worldIn, BlockPos pos, BlockState state, @Nullable LivingEntity placer, ItemStack stack) { super.onBlockPlacedBy(worldIn, pos, state, placer, stack); RedstoneTransmitterList.get(worldIn).setTransmitter(worldIn, pos, state.getValues().get(ID).toString()); } @Override public void onReplaced(BlockState state, World worldIn, BlockPos pos, BlockState newState, boolean isMoving) { super.onReplaced(state, worldIn, pos, newState, isMoving); RedstoneTransmitterList.get(worldIn).setTransmitter(worldIn, pos, null); } }
  2. Well. I fixed my errors, thank you all for your help. Regards Aaron
  3. Well my Goal is that if I flick my custom lever my receiver should send out the same power signal. I made an IntegerProperty called power but I get this error: [19:14:40] [Render thread/ERROR] [ne.mi.fm.ja.FMLModContainer/]: Exception caught during firing event: Cannot set property IntegerProperty{name=power, clazz=class java.lang.Integer, values=[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]} as it does not exist in Block{null} My class: public class RedstoneReceiverBlock extends Block { public static final IntegerProperty POWER = IntegerProperty.create("power", 0, 15); public RedstoneReceiverBlock() { super(AbstractBlock.Properties.create(Material.IRON, MaterialColor.EMERALD)); this.setDefaultState(this.getStateContainer().getBaseState().with(POWER, Integer.valueOf(0))); } @Override public boolean canProvidePower(BlockState state) { return true; } @Override public boolean canConnectRedstone(BlockState state, IBlockReader world, BlockPos pos, Direction side) { return true; } @Override public int getWeakPower(BlockState blockState, IBlockReader blockAccess, BlockPos pos, Direction side) { return blockState.get(POWER); } } My method which changes Power: public static void switchState(World w, BlockPos pos) { BlockState state = w.getBlockState(pos); if(isPowered(w, pos)) { w.setBlockState(pos, RegistryHandler.REDSTONE_RECEIVER.get().getDefaultState().with(RedstoneReceiverBlock.POWER, 0)); }else{ w.setBlockState(pos, RegistryHandler.REDSTONE_RECEIVER.get().getDefaultState().with(RedstoneReceiverBlock.POWER, 15)); } } Regards
  4. Thank you for the answer it really helped me out. So I managed to power the block by default, may you tell me how I can modify getWeakPower() to 0 in another class? Regards Aaron
  5. Thank you for you answer, so I set my Receiver to an RedstoneBlock and changed the canProvidePower Property to false, but it sends out a Redstone Signal anyways, and even if I can change it, that it doesn't send out a Redstone Signal, how can I set it back. Since I don't want to wait for an answer and you don't want to answer my questions; Do you have a good Documention about the Forge API so I can get into this myself? Regards
  6. Hey, I already made a transmitter in form of a lever, but I want my receiver to always have the same power state than my transmitter. I don't quite now what you think of but a lever. Aaron
  7. Dear Modding Community so I am working on a Mod which requires Wireless Redstone. How can I make a Redstone Output on my custome Receiver Block and turn it on and off. Thank you in advance Aaron
  8. Sure, here we go: (The debug.log is too big as a file, a text, or a pastebin) latest.log found a way: https://justpaste.it/4noeh
  9. Dear Modding Community, I started Modding with Minecraft Version 1.15.2, however when i updated to 1.16.3 i ran into an error (see title). I couldn't find anything in the forum, I'll post the whole crash log as an attachment. Looks like something is wrong with the mods.toml file, but i couldn't find any errors. Thank you in advance Aaron crash-2020-10-11_11.45.48-fml.txt
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.