-
Notifications
You must be signed in to change notification settings - Fork 35
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
96d8ca3
commit 4982e94
Showing
20 changed files
with
889 additions
and
14 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package me.gleep.oreganized.blocks; | ||
|
||
import me.gleep.oreganized.util.RegistryHandler; | ||
import net.minecraft.block.Block; | ||
import net.minecraft.block.BlockState; | ||
import net.minecraft.state.IntegerProperty; | ||
import net.minecraft.state.StateContainer; | ||
import net.minecraft.tileentity.TileEntity; | ||
import net.minecraft.world.IBlockReader; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
public class StoneSign extends Block { | ||
private static final IntegerProperty PROGRESS = IntegerProperty.create("progress", 0, 8);; | ||
|
||
public StoneSign(Properties properties) { | ||
super(properties); | ||
setDefaultState(this.getDefaultState().with(PROGRESS, 0)); | ||
} | ||
|
||
@Override | ||
protected void fillStateContainer(StateContainer.Builder<Block, BlockState> builder) { | ||
builder.add(PROGRESS); | ||
} | ||
|
||
/** | ||
* Called throughout the code as a replacement for block instanceof BlockContainer | ||
* Moving this to the Block base class allows for mods that wish to extend vanilla | ||
* blocks, and also want to have a tile entity on that block, may. | ||
* <p> | ||
* Return true from this function to specify this block has a tile entity. | ||
* | ||
* @param state State of the current block | ||
* @return True if block has a tile entity, false otherwise | ||
*/ | ||
@Override | ||
public boolean hasTileEntity(BlockState state) { | ||
return true; | ||
} | ||
|
||
/** | ||
* Called throughout the code as a replacement for ITileEntityProvider.createNewTileEntity | ||
* Return the same thing you would from that function. | ||
* This will fall back to ITileEntityProvider.createNewTileEntity(World) if this block is a ITileEntityProvider | ||
* | ||
* @param state The state of the current block | ||
* @param world The world to create the TE in | ||
* @return A instance of a class extending TileEntity | ||
*/ | ||
@Nullable | ||
@Override | ||
public TileEntity createTileEntity(BlockState state, IBlockReader world) { | ||
return RegistryHandler.STONE_SIGN_TE.get().create(); | ||
} | ||
} |
76 changes: 76 additions & 0 deletions
76
src/main/java/me/gleep/oreganized/entities/entityrenderer/StoneSignRenderer.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,76 @@ | ||
package me.gleep.oreganized.entities.entityrenderer; | ||
|
||
import com.mojang.blaze3d.matrix.MatrixStack; | ||
import com.mojang.blaze3d.vertex.IVertexBuilder; | ||
import java.util.List; | ||
|
||
import me.gleep.oreganized.blocks.StoneSign; | ||
import me.gleep.oreganized.entities.tileentities.StoneSignTileEntity; | ||
import net.minecraft.block.AbstractSignBlock; | ||
import net.minecraft.block.Block; | ||
import net.minecraft.block.BlockState; | ||
import net.minecraft.block.StandingSignBlock; | ||
import net.minecraft.block.WallSignBlock; | ||
import net.minecraft.block.WoodType; | ||
import net.minecraft.block.material.Material; | ||
import net.minecraft.client.gui.FontRenderer; | ||
import net.minecraft.client.renderer.Atlases; | ||
import net.minecraft.client.renderer.BlockModelRenderer; | ||
import net.minecraft.client.renderer.IRenderTypeBuffer; | ||
import net.minecraft.client.renderer.RenderType; | ||
import net.minecraft.client.renderer.model.Model; | ||
import net.minecraft.client.renderer.model.ModelRenderer; | ||
import net.minecraft.client.renderer.model.RenderMaterial; | ||
import net.minecraft.client.renderer.texture.NativeImage; | ||
import net.minecraft.client.renderer.tileentity.TileEntityRenderer; | ||
import net.minecraft.client.renderer.tileentity.TileEntityRendererDispatcher; | ||
import net.minecraft.tileentity.SignTileEntity; | ||
import net.minecraft.util.IReorderingProcessor; | ||
import net.minecraft.util.math.vector.Vector3f; | ||
import net.minecraftforge.api.distmarker.Dist; | ||
import net.minecraftforge.api.distmarker.OnlyIn; | ||
import net.minecraftforge.client.model.generators.BlockModelBuilder; | ||
|
||
@OnlyIn(Dist.CLIENT) | ||
public class StoneSignRenderer extends TileEntityRenderer<StoneSignTileEntity> { | ||
public StoneSignRenderer(TileEntityRendererDispatcher rendererDispatcherIn) { | ||
super(rendererDispatcherIn); | ||
} | ||
|
||
@Override | ||
public void render(StoneSignTileEntity tileEntityIn, float partialTicks, MatrixStack matrixStackIn, IRenderTypeBuffer bufferIn, int combinedLightIn, int combinedOverlayIn) { | ||
BlockState blockstate = tileEntityIn.getBlockState(); | ||
matrixStackIn.push(); | ||
float f = 0.6666667F; | ||
matrixStackIn.translate(0.5D, 0.5D, 0.5D); | ||
matrixStackIn.translate(0.0D, -0.3125D, 0.5D); | ||
|
||
matrixStackIn.push(); | ||
matrixStackIn.scale(0.6666667F, -0.6666667F, -0.6666667F); | ||
matrixStackIn.pop(); | ||
FontRenderer fontrenderer = this.renderDispatcher.getFontRenderer(); | ||
float f2 = 0.010416667F; | ||
matrixStackIn.translate(0.0D, (double)0.33333334F, 0.04D); | ||
matrixStackIn.scale(0.010416667F, -0.010416667F, 0.010416667F); | ||
int i = tileEntityIn.getTextColor().getTextColor(); | ||
double d0 = 0.4D; | ||
int j = (int)((double)NativeImage.getRed(i) * 0.4D); | ||
int k = (int)((double)NativeImage.getGreen(i) * 0.4D); | ||
int l = (int)((double)NativeImage.getBlue(i) * 0.4D); | ||
int i1 = NativeImage.getCombined(0, l, k, j); | ||
int j1 = 20; | ||
|
||
for(int k1 = 0; k1 < 6; ++k1) { | ||
IReorderingProcessor ireorderingprocessor = tileEntityIn.func_242686_a(k1, (p_243502_1_) -> { | ||
List<IReorderingProcessor> list = fontrenderer.trimStringToWidth(p_243502_1_, 80); | ||
return list.isEmpty() ? IReorderingProcessor.field_242232_a : list.get(0); | ||
}); | ||
if (ireorderingprocessor != null) { | ||
float f3 = (float)(-fontrenderer.func_243245_a(ireorderingprocessor) / 2); | ||
fontrenderer.func_238416_a_(ireorderingprocessor, f3, (float)(k1 * 10 - 20), i1, false, matrixStackIn.getLast().getMatrix(), bufferIn, false, 0, combinedLightIn); | ||
} | ||
} | ||
|
||
matrixStackIn.pop(); | ||
} | ||
} |
181 changes: 181 additions & 0 deletions
181
src/main/java/me/gleep/oreganized/entities/tileentities/StoneSignTileEntity.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,181 @@ | ||
package me.gleep.oreganized.entities.tileentities; | ||
|
||
import com.mojang.brigadier.exceptions.CommandSyntaxException; | ||
import java.util.function.Function; | ||
import javax.annotation.Nullable; | ||
|
||
import me.gleep.oreganized.util.RegistryHandler; | ||
import net.minecraft.block.BlockState; | ||
import net.minecraft.command.CommandSource; | ||
import net.minecraft.command.ICommandSource; | ||
import net.minecraft.entity.Entity; | ||
import net.minecraft.entity.player.PlayerEntity; | ||
import net.minecraft.entity.player.ServerPlayerEntity; | ||
import net.minecraft.item.DyeColor; | ||
import net.minecraft.nbt.CompoundNBT; | ||
import net.minecraft.network.NetworkManager; | ||
import net.minecraft.network.play.server.SUpdateTileEntityPacket; | ||
import net.minecraft.tileentity.TileEntity; | ||
import net.minecraft.tileentity.TileEntityType; | ||
import net.minecraft.util.IReorderingProcessor; | ||
import net.minecraft.util.math.vector.Vector2f; | ||
import net.minecraft.util.math.vector.Vector3d; | ||
import net.minecraft.util.text.ITextComponent; | ||
import net.minecraft.util.text.StringTextComponent; | ||
import net.minecraft.util.text.Style; | ||
import net.minecraft.util.text.TextComponentUtils; | ||
import net.minecraft.util.text.event.ClickEvent; | ||
import net.minecraft.world.server.ServerWorld; | ||
import net.minecraftforge.api.distmarker.Dist; | ||
import net.minecraftforge.api.distmarker.OnlyIn; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
public class StoneSignTileEntity extends TileEntity { | ||
private final ITextComponent[] signText = new ITextComponent[]{StringTextComponent.EMPTY, StringTextComponent.EMPTY, StringTextComponent.EMPTY, StringTextComponent.EMPTY, StringTextComponent.EMPTY, StringTextComponent.EMPTY}; | ||
private boolean isEditable = true; | ||
private PlayerEntity player; | ||
private final IReorderingProcessor[] renderText = new IReorderingProcessor[6]; | ||
private DyeColor textColor = DyeColor.BLACK; | ||
|
||
public StoneSignTileEntity() { | ||
super(RegistryHandler.STONE_SIGN_TE.get()); | ||
} | ||
|
||
@NotNull | ||
@Override | ||
public CompoundNBT write(CompoundNBT compound) { | ||
super.write(compound); | ||
|
||
for(int i = 0; i < 6; ++i) { | ||
String s = ITextComponent.Serializer.toJson(this.signText[i]); | ||
compound.putString("Text" + (i + 1), s); | ||
} | ||
|
||
compound.putString("Color", this.textColor.getTranslationKey()); | ||
return compound; | ||
} | ||
|
||
@Override | ||
public void read(BlockState state, CompoundNBT nbt) { | ||
this.isEditable = false; | ||
super.read(state, nbt); | ||
this.textColor = DyeColor.byTranslationKey(nbt.getString("Color"), DyeColor.BLACK); | ||
|
||
for(int i = 0; i < 6; ++i) { | ||
String s = nbt.getString("Text" + (i + 1)); | ||
ITextComponent itextcomponent = ITextComponent.Serializer.getComponentFromJson(s.isEmpty() ? "\"\"" : s); | ||
if (this.world instanceof ServerWorld) { | ||
try { | ||
this.signText[i] = TextComponentUtils.func_240645_a_(this.getCommandSource((ServerPlayerEntity)null), itextcomponent, (Entity)null, 0); | ||
} catch (CommandSyntaxException commandsyntaxexception) { | ||
this.signText[i] = itextcomponent; | ||
} | ||
} else { | ||
this.signText[i] = itextcomponent; | ||
} | ||
|
||
this.renderText[i] = null; | ||
} | ||
|
||
} | ||
|
||
@OnlyIn(Dist.CLIENT) | ||
public ITextComponent getText(int line) { | ||
return this.signText[line]; | ||
} | ||
|
||
public void setText(int line, ITextComponent signText) { | ||
this.signText[line] = signText; | ||
this.renderText[line] = null; | ||
} | ||
|
||
@Nullable | ||
@OnlyIn(Dist.CLIENT) | ||
public IReorderingProcessor func_242686_a(int p_242686_1_, Function<ITextComponent, IReorderingProcessor> p_242686_2_) { | ||
if (this.renderText[p_242686_1_] == null && this.signText[p_242686_1_] != null) { | ||
this.renderText[p_242686_1_] = p_242686_2_.apply(this.signText[p_242686_1_]); | ||
} | ||
|
||
return this.renderText[p_242686_1_]; | ||
} | ||
|
||
/** | ||
* Retrieves packet to send to the client whenever this Tile Entity is resynced via World.notifyBlockUpdate. For | ||
* modded TE's, this packet comes back to you clientside in {@link #onDataPacket} | ||
*/ | ||
@Nullable | ||
@Override | ||
public SUpdateTileEntityPacket getUpdatePacket() { | ||
return new SUpdateTileEntityPacket(this.pos, 9, this.getUpdateTag()); | ||
} | ||
|
||
/** | ||
* Get an NBT compound to sync to the client with SPacketChunkData, used for initial loading of the chunk or when | ||
* many blocks change at once. This compound comes back to you clientside in {@link handleUpdateTag} | ||
*/ | ||
@Override | ||
public CompoundNBT getUpdateTag() { | ||
return this.write(new CompoundNBT()); | ||
} | ||
|
||
/** | ||
* Checks if players can use this tile entity to access operator (permission level 2) commands either directly or | ||
* indirectly, such as give or setblock. A similar method exists for entities at {@link | ||
* net.minecraft.entity.Entity#ignoreItemEntityData()}.<p>For example, {@link | ||
* net.minecraft.tileentity.TileEntitySign#onlyOpsCanSetNbt() signs} (player right-clicking) and {@link | ||
* net.minecraft.tileentity.TileEntityCommandBlock#onlyOpsCanSetNbt() command blocks} are considered | ||
* accessible.</p>@return true if this block entity offers ways for unauthorized players to use restricted commands | ||
*/ | ||
@Override | ||
public boolean onlyOpsCanSetNbt() { | ||
return true; | ||
} | ||
|
||
public boolean getIsEditable() { | ||
return this.isEditable; | ||
} | ||
|
||
/** | ||
* Sets the sign's isEditable flag to the specified parameter. | ||
*/ | ||
@OnlyIn(Dist.CLIENT) | ||
public void setEditable(boolean isEditableIn) { | ||
this.isEditable = isEditableIn; | ||
if (!isEditableIn) { | ||
this.player = null; | ||
} | ||
|
||
} | ||
|
||
public void setPlayer(PlayerEntity playerIn) { | ||
this.player = playerIn; | ||
} | ||
|
||
public PlayerEntity getPlayer() { | ||
return this.player; | ||
} | ||
|
||
public boolean executeCommand(PlayerEntity playerIn) { | ||
for(ITextComponent itextcomponent : this.signText) { | ||
Style style = itextcomponent == null ? null : itextcomponent.getStyle(); | ||
if (style != null && style.getClickEvent() != null) { | ||
ClickEvent clickevent = style.getClickEvent(); | ||
if (clickevent.getAction() == ClickEvent.Action.RUN_COMMAND) { | ||
playerIn.getServer().getCommandManager().handleCommand(this.getCommandSource((ServerPlayerEntity)playerIn), clickevent.getValue()); | ||
} | ||
} | ||
} | ||
|
||
return true; | ||
} | ||
|
||
public CommandSource getCommandSource(@Nullable ServerPlayerEntity playerIn) { | ||
String s = playerIn == null ? "StoneSign" : playerIn.getName().getString(); | ||
ITextComponent itextcomponent = (ITextComponent)(playerIn == null ? new StringTextComponent("StoneSign") : playerIn.getDisplayName()); | ||
return new CommandSource(ICommandSource.DUMMY, Vector3d.copyCentered(this.pos), Vector2f.ZERO, (ServerWorld)this.world, 2, s, itextcomponent, this.world.getServer(), playerIn); | ||
} | ||
|
||
public DyeColor getTextColor() { | ||
return this.textColor; | ||
} | ||
} |
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
Oops, something went wrong.