-
Notifications
You must be signed in to change notification settings - Fork 105
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
88fc68b
commit 61b7677
Showing
15 changed files
with
235 additions
and
4 deletions.
There are no files selected for viewing
7 changes: 7 additions & 0 deletions
7
src/generated/resources/assets/enderio/blockstates/painted_travel_anchor.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"variants": { | ||
"": { | ||
"model": "enderio:block/painted_travel_anchor" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 4 additions & 0 deletions
4
src/generated/resources/assets/enderio/models/block/painted_travel_anchor.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"loader": "enderio:painted_block", | ||
"reference": "minecraft:dirt" | ||
} |
3 changes: 3 additions & 0 deletions
3
src/generated/resources/assets/enderio/models/item/painted_travel_anchor.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"parent": "enderio:block/painted_travel_anchor" | ||
} |
29 changes: 29 additions & 0 deletions
29
src/generated/resources/data/enderio/loot_tables/blocks/painted_travel_anchor.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
{ | ||
"type": "minecraft:block", | ||
"pools": [ | ||
{ | ||
"bonus_rolls": 0.0, | ||
"entries": [ | ||
{ | ||
"type": "minecraft:item", | ||
"functions": [ | ||
{ | ||
"function": "minecraft:copy_nbt", | ||
"ops": [ | ||
{ | ||
"op": "replace", | ||
"source": "Paint", | ||
"target": "BlockEntityTag.Paint" | ||
} | ||
], | ||
"source": "block_entity" | ||
} | ||
], | ||
"name": "enderio:painted_travel_anchor" | ||
} | ||
], | ||
"rolls": 1.0 | ||
} | ||
], | ||
"random_sequence": "enderio:blocks/painted_travel_anchor" | ||
} |
7 changes: 7 additions & 0 deletions
7
src/generated/resources/data/enderio/recipes/painting/painted_travel_anchor.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"type": "enderio:painting", | ||
"input": { | ||
"item": "enderio:travel_anchor" | ||
}, | ||
"output": "enderio:painted_travel_anchor" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
src/machines/java/com/enderio/machines/common/block/PaintedTravelAnchorBlock.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package com.enderio.machines.common.block; | ||
|
||
import com.enderio.base.common.block.painted.IPaintedBlock; | ||
import com.enderio.machines.common.blockentity.PaintedTravelAnchorBlockEntity; | ||
import com.enderio.machines.common.init.MachineBlockEntities; | ||
import net.minecraft.core.BlockPos; | ||
import net.minecraft.core.Direction; | ||
import net.minecraft.world.entity.player.Player; | ||
import net.minecraft.world.item.ItemStack; | ||
import net.minecraft.world.level.BlockAndTintGetter; | ||
import net.minecraft.world.level.BlockGetter; | ||
import net.minecraft.world.level.LevelReader; | ||
import net.minecraft.world.level.block.Block; | ||
import net.minecraft.world.level.block.Blocks; | ||
import net.minecraft.world.level.block.entity.BlockEntity; | ||
import net.minecraft.world.level.block.state.BlockState; | ||
import net.minecraft.world.phys.HitResult; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
public class PaintedTravelAnchorBlock extends TravelAnchorBlock implements IPaintedBlock { | ||
|
||
public PaintedTravelAnchorBlock(Properties props) { | ||
super(props); | ||
} | ||
|
||
@Nullable | ||
@Override | ||
public BlockEntity newBlockEntity(BlockPos pPos, BlockState pState) { | ||
return MachineBlockEntities.PAINTED_TRAVEL_ANCHOR.create(pPos, pState); | ||
} | ||
|
||
@Override | ||
public ItemStack getCloneItemStack(BlockState state, HitResult target, LevelReader level, BlockPos pos, Player player) { | ||
return getPaintedStack(level, pos, this); | ||
} | ||
|
||
@Override | ||
public BlockState getAppearance(BlockState state, BlockAndTintGetter level, BlockPos pos, Direction side, @Nullable BlockState queryState, | ||
@Nullable BlockPos queryPos) { | ||
if (level.getBlockEntity(pos) instanceof PaintedTravelAnchorBlockEntity painted && painted.getPaint() != null) { | ||
return painted.getPaint().defaultBlockState(); | ||
} | ||
return super.getAppearance(state, level, pos, side, queryState, queryPos); | ||
} | ||
|
||
@Override | ||
public Block getPaint(BlockGetter level, BlockPos pos) { | ||
if (level.getBlockEntity(pos) instanceof PaintedTravelAnchorBlockEntity paintedBlockEntity) { | ||
Block paint = paintedBlockEntity.getPaint(); | ||
if (paint != null && !(paint instanceof IPaintedBlock)) { | ||
return paint; | ||
} | ||
} | ||
//sane default (definitely not air) | ||
return Blocks.OAK_PLANKS; | ||
} | ||
} |
99 changes: 99 additions & 0 deletions
99
...machines/java/com/enderio/machines/common/blockentity/PaintedTravelAnchorBlockEntity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
package com.enderio.machines.common.blockentity; | ||
|
||
import com.enderio.base.EIONBTKeys; | ||
import com.enderio.base.common.blockentity.IPaintableBlockEntity; | ||
import com.enderio.base.common.blockentity.SinglePaintedBlockEntity; | ||
import com.enderio.base.common.util.PaintUtils; | ||
import com.enderio.machines.common.init.MachineBlockEntities; | ||
import net.minecraft.core.BlockPos; | ||
import net.minecraft.core.registries.BuiltInRegistries; | ||
import net.minecraft.nbt.CompoundTag; | ||
import net.minecraft.network.Connection; | ||
import net.minecraft.network.protocol.game.ClientboundBlockEntityDataPacket; | ||
import net.minecraft.world.level.block.Block; | ||
import net.minecraft.world.level.block.state.BlockState; | ||
import net.neoforged.neoforge.client.model.data.ModelData; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
import java.util.Objects; | ||
|
||
public class PaintedTravelAnchorBlockEntity extends TravelAnchorBlockEntity implements IPaintableBlockEntity { | ||
|
||
@Nullable | ||
private Block paint; | ||
|
||
public PaintedTravelAnchorBlockEntity(BlockPos pWorldPosition, BlockState pBlockState) { | ||
super(MachineBlockEntities.PAINTED_TRAVEL_ANCHOR.get(), pWorldPosition, pBlockState); | ||
} | ||
|
||
public ModelData getModelData() { | ||
return ModelData.builder().with(SinglePaintedBlockEntity.PAINT, getPaint()).build(); | ||
} | ||
|
||
@Override | ||
public Block getPaint() { | ||
return paint; | ||
} | ||
|
||
@Nullable | ||
@Override | ||
public ClientboundBlockEntityDataPacket getUpdatePacket() { | ||
return ClientboundBlockEntityDataPacket.create(this); | ||
} | ||
|
||
@Override | ||
public void onDataPacket(Connection net, ClientboundBlockEntityDataPacket pkt) { | ||
Block oldPaint = paint; | ||
CompoundTag tag = pkt.getTag(); | ||
if (tag == null) { | ||
return; | ||
} | ||
|
||
handleUpdateTag(tag); | ||
if (oldPaint != paint) { | ||
requestModelDataUpdate(); | ||
if (level != null) { | ||
level.setBlock(getBlockPos(), level.getBlockState(getBlockPos()), 9); | ||
} | ||
} | ||
} | ||
|
||
@Override | ||
public void load(CompoundTag tag) { | ||
super.load(tag); | ||
readPaint(tag); | ||
} | ||
|
||
@Override | ||
public CompoundTag getUpdateTag() { | ||
CompoundTag nbt = super.getUpdateTag(); | ||
writePaint(nbt); | ||
return nbt; | ||
} | ||
|
||
// TODO: HOUSEKEEPING?: This should probably be converted to a capability. | ||
protected void readPaint(CompoundTag tag) { | ||
if (tag.contains(EIONBTKeys.PAINT)) { | ||
paint = PaintUtils.getBlockFromRL(tag.getString(EIONBTKeys.PAINT)); | ||
if (level != null) { | ||
if (level.isClientSide) { | ||
requestModelDataUpdate(); | ||
level.sendBlockUpdated(getBlockPos(), getBlockState(), getBlockState(), | ||
Block.UPDATE_NEIGHBORS + Block.UPDATE_CLIENTS); | ||
} | ||
} | ||
} | ||
} | ||
|
||
@Override | ||
public void saveAdditional(CompoundTag tag) { | ||
super.saveAdditional(tag); | ||
writePaint(tag); | ||
} | ||
|
||
protected void writePaint(CompoundTag tag) { | ||
if (paint != null) { | ||
tag.putString(EIONBTKeys.PAINT, Objects.requireNonNull(BuiltInRegistries.BLOCK.getKey(paint)).toString()); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters